You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
PersistentState does not work between enhanced navigation SSR and WASM pages #63895
Is your feature request related to a problem? Please describe the problem.
If I navigate from a SSR page with enhanced navigation to a WASM page (@rendermode InteractiveWebAssembly at the top), the PersistentState feature doesn't work.
There is a mention of this in the docs (although it's not clear whether this is an interactive routing) "If the app adopts interactive routing and the page is reached via an internal enhanced navigation, prerendering doesn't occur. Therefore, you must perform a full page reload for the component to see the following output."
But there is also this in the docs: "Blazor supports handling persistent component state during enhanced navigation. State persisted during enhanced navigation can be read by interactive components on the page."
So is it so that the PersistentState feature is intentionally not meant to work in this situation, and that all pages should be SSR rendered with only Components marked with @rendermode="InteractiveWebAssembly"?
If yes, could this be mentioned in the docs? And is this feature possible to implement in the future?
Describe the solution you'd like
I would like PersistentState to work between enhanced navigation SSR and WASM pages.
If you navigate between the Home and Counter page a few times, you see that on each navigation to Counter page the CounterClientService is invoked (in browser console and network tabs), which in turn calls the API endpoint, even though there is no need, representing a duplicate invocation of for example a database call.
I tried all variations of the PersistentState properties, but I could not see a difference.
Disabling enhanced navigation in App.razor solves this issue, but it is another thing that new Blazor developers won't know about.
Would be great if this could work without that.
From what I can observe right now, something weird is going on that has to do with some persistent component state updates being lost. (see the warnings). I suspect this might be an issue on the JS bits that collect the state, and would explain why our E2E tests didn't necessarily catch this.
Here we can see a couple of successful transitions
info: BlazorApp4.Components.Pages.Home[0] Rendering Home. Renderer: Staticinfo: BlazorApp4.Client.Pages.Counter[0] Name: Static, State: nullinfo: BlazorApp4.CounterServerService[0] Called from Static. Generated count: 164info: BlazorApp4.Client.Pages.Counter[0] Name: Server, State: 164info: BlazorApp4.Client.Pages.Counter[0] Finished rendering: Server with count: 164info: BlazorApp4.Components.Pages.Weather[0] Starting to load weather data. Renderer: Staticinfo: BlazorApp4.Client.Pages.Counter[0] Name: Static, State: nullinfo: BlazorApp4.CounterServerService[0] Called from Static. Generated count: 147info: BlazorApp4.Client.Pages.Counter[0] Name: Server, State: 147info: BlazorApp4.Client.Pages.Counter[0] Finished rendering: Server with count: 147info: BlazorApp4.Components.Pages.Home[0] Rendering Home. Renderer: Static
Here we see an example where things go wrong
info: BlazorApp4.Client.Pages.Counter[0] Name: Static, State: nullinfo: BlazorApp4.CounterServerService[0] Called from Static. Generated count: 102warn: BlazorApp4.Client.Pages.Counter[0] Name: Server, State: nullinfo: BlazorApp4.CounterServerService[0] Called from Server. Generated count: 124info: BlazorApp4.Client.Pages.Counter[0] Finished rendering: Server with count: 124
Reacted by Markz878, wendellestradairely, boukenka and Dzmitry Matveyeu
@javiercn Glad you were able to track down the bug. I suppose this will be a common pattern in SSR + WASM scenarios, so I agree it's important to get it fixed for 10.0. Thanks for your effort!
@javiercn@danroth27 Why doesn't any template you have show this simple data access pattern for a SSR+WASM Blazor app? You expect developers to come up with our own patterns for this, but even this simple pattern has a bug in it. If you would dogfood your own framework even a little bit you would notice these kinds of problems.
I'm very disappointed that this wasn't fixed for .NET 10, is it going to be another 2 years for this to be fixed for LTS release?
How is Blazor ever going to get any serious traction with bugs like this?
I get what I think is a similar issue (but with SSR and InteractiveServer) where I have a scoped service registered with persistence in the Program.cs. Values marked with [PersistentState] carry over between SSR and InteractiveServer rendering as expected. However as soon as I run code via OnAfterRender the service is back to default values, it didn't persist.
Activity
MihuBot commentedon Oct 1, 2025
I'm a bot. Here are possible related and/or duplicate issues (I may be wrong):
javiercn commentedon Oct 1, 2025
@Markz878 thanks for contacting us.
Can you provide a minimal repro project that demonstrates the issue?
Markz878 commentedon Oct 1, 2025
@javiercn Here is the repro project:
https://github.com/Markz878/PersistentStateIssue
If you navigate between the Home and Counter page a few times, you see that on each navigation to Counter page the CounterClientService is invoked (in browser console and network tabs), which in turn calls the API endpoint, even though there is no need, representing a duplicate invocation of for example a database call.
I tried all variations of the PersistentState properties, but I could not see a difference.
Disabling enhanced navigation in App.razor solves this issue, but it is another thing that new Blazor developers won't know about.
Would be great if this could work without that.
javiercn commentedon Oct 2, 2025
@Markz878 thanks for the additional details.
From what I can observe right now, something weird is going on that has to do with some persistent component state updates being lost. (see the warnings). I suspect this might be an issue on the JS bits that collect the state, and would explain why our E2E tests didn't necessarily catch this.
Here we can see a couple of successful transitions
Here we see an example where things go wrong
Markz878 commentedon Oct 2, 2025
@javiercn Glad you were able to track down the bug. I suppose this will be a common pattern in SSR + WASM scenarios, so I agree it's important to get it fixed for 10.0. Thanks for your effort!
AlexKovynev commentedon Oct 12, 2025
@javiercn maybe better move to 10.0.0 milestone cause here nothing resolved :(
Markz878 commentedon Oct 31, 2025
@javiercn Could you tell what is the status on this, are we getting a fix for this in .NET 10?
Markz878 commentedon Nov 11, 2025
@javiercn @danroth27 Why doesn't any template you have show this simple data access pattern for a SSR+WASM Blazor app? You expect developers to come up with our own patterns for this, but even this simple pattern has a bug in it. If you would dogfood your own framework even a little bit you would notice these kinds of problems.
I'm very disappointed that this wasn't fixed for .NET 10, is it going to be another 2 years for this to be fixed for LTS release?
How is Blazor ever going to get any serious traction with bugs like this?
danroth27 commentedon Nov 11, 2025
@Markz878 We've queued this up for investigation for a potential .NET 10 servicing release.
MrScottyTay commentedon Feb 17, 2026
Any traction on this yet?
I get what I think is a similar issue (but with SSR and InteractiveServer) where I have a scoped service registered with persistence in the Program.cs. Values marked with [PersistentState] carry over between SSR and InteractiveServer rendering as expected. However as soon as I run code via OnAfterRender the service is back to default values, it didn't persist.
[Blazor] Fix persisted state being dropped on enhanced navigation (#6…