-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Blazor Pre-rendering and PersistingComponentStateSubscription not working correctly with dotnet 9 with InteractiveServer mode? #59198
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@MattCost thanks for contacting us. Based on your repro, this seems a dupe of #51584 PersistentComponentState only works on the initial navigation, not during enhanced navigations. Your repo sets up per-page interactivity, which is why I suspect that when you visit the weather forecast page directly it works, but when you click on it through enhanced navigation it doesn't. |
Just mentioning in passing that we have it covered thus far by NOTEs in the article that advise devs ...
... referring to the examples shown. The first NOTE pertains to I'm 👂 to see if we'll need to "enhance" the remark on enhanced routing. |
I am confused by that note. So yes, you need to enhance the note on enhanced routing. To be honest, I have no idea if I am using Static or Interactive routing. This page makes it seem like that is controlled by the blazor runtime? Assuming the app does switch to interactive routing because the page is using interactiveServer mode, then I believe the bug report still stands. The app should switch to using interactive routing, and the page IS reached via an internal navigation. So pre-rendering should not occur. Got it. BUT I am seeing the app show "Loading..." then seeing the data populate twice, despite having the Save stage code in place. Sample repo linked in original comment was created using |
If you say this is a dupe of that existing issue, I'll take your word for it.
I am an experienced c# dev, but this is my first use of blazer. I am not trying to be rude, but my honest feedback is that I find getting into blazor terribly confusing. Even a "simple" page requires a somewhat deep understanding of all the intraicies of blazor functionality. Could I create a page with a ServerRender mode, and utilize PersistentComponentState, but have the page contain a blazor component rendered in interactive mode? |
@MattCosturos thanks, I think the option on the template sent you the wrong way. Per page interactivity is more powerful yet more complex. If you want simplicity, I'd recommend starting with server and global interactivity. |
@javiercn Closing this issue, since there is already an active issue |
@MattCost apologies, I wanted to give you a more detailed response, but it seems that I didn't hit send. I'm leaving it here, since it explains in more details what's going on. https://github.com/MattCost/blazorTest/blob/main/Components/App.razor#L17 <- Your
With per page navigation, navigations are handled by The first time, is the page rendering on the server as a result of enhanced navigation. The bug that I pointed out covers precisely the situation you are describing. In an enhanced navigation request, the state in The main reason here being that we only ever supported passing state from the server to the client at the time the runtime initializes, and not after it has already been running. |
I was stuck with this issue for hours today. Could you please clarify few more things, because it still does not make sense for me.
So, the page is first still rendered on the server even with enhanced navigation? And the docs says that pre-rendering does not happen in case of enhanced navigation. This is really confusing. If that is not a pre-render, then what is that and why does it happen at the first place?
Well, I can clearly see base64 encoded state in the web-page when PersistentComponentState returns nothing.
|
Is there an existing issue for this?
Describe the bug
Using dotnet 9, blazor with InteractiveServer mode, The PersistingComponentStateSubscription does not seem to work as expected.
After creating a new blazor app from a template, and following the docs to add the PersistingComponentStateSubscription functionality, the page does not work as expected.
Sometimes the state is saved and the page loads correctly, however, most times the render phase will see an empty state, despite the pre-rendering phase saving the data to the ApplicationState.
Questions
Why does the persisting only work sometimes when InteractiveAuto mode is used?
Leaving the
InteractiveAuto
annotation off the page allows the state to be saved correctly, but well we lose the interactive nature of blazor.cc: @guardrex dotnet/AspNetCore.Docs#34229
Expected Behavior
PersistingComponentState works every page load when using InteractiveServer mode + PreRendering, or an alternative setup is documented.
Steps To Reproduce
Sample Repo
Steps to reproduce
@rendermode InteractiveServer
to the weather pageExceptions (if any)
No response
.NET Version
9.0.100
Anything else?
The text was updated successfully, but these errors were encountered: