StreamRendering and RenderModeServer causes OnInitialized to be invoked twice. Second time query parameter not bound.
See original GitHub issueIs there an existing issue for this?
- I have searched the existing issues
Describe the bug
Interactive Server page with attributes StreamRendering(true)
and RenderModeServer
causes OnInitialized
/OnInitializedAsync
to be invoked twice.
Taking a normal route parameter and a parameter supplied from query (using SupplyParameterFromQuery
).
Invoking the page with fresh navigation using query parameter causes the OnInitialized
method to be invoked twice. The second time the query parameter is not bound. Though the regular route parameter is.
Expected Behavior
The parameter should be bound from query.
Question: <strike>Should OnInitialized
be invoked twice? I thought only OnAfterRender
ran twice while the server component being the same. </strike>
I see, the component object is not being re-used from the pre-render.
Steps To Reproduce
Doing a fresh navigation to: /test/x?queryParam=test
@page "/test/{path?}"
@attribute [StreamRendering(true)]
@attribute [RenderModeServer]
@QueryParam
@code
{
[Parameter]
public string? Param { get; set; }
[SupplyParameterFromQuery]
public string? QueryParam { get; set; }
protected override void OnInitialized()
{
// Method called twice
// First time the value of QueryParam is set to "test", and Param is "x"
// The second time the value of QueryParam is null, but Param is "x"
Console.WriteLine(QueryParam);
}
}
First time hitting break-point:
Second time:
Exceptions (if any)
No response
.NET Version
8.0.100-preview.6.23330.14
Anything else?
No response
Issue Analytics
- State:
- Created 2 months ago
- Comments:11 (3 by maintainers)
@marinasundstrom no, that should work.
I am not sure why is not working, but there has been a lot of churn in this area during preview7, so I would suggest you try a nightly build.
@marinasundstrom thanks for contacting us.
OnInitialized
will execute once during prerendering, and once again when the component becomes interactive. During prerendering a render process starts, and once we are done prerendering, it stops, disposing all the prerendered components.Then, for components that have either server or webassembly mode, the components are re-created again and produce a new render to become interactive (that’s where the OnInitialized runs for the second time).