-
Notifications
You must be signed in to change notification settings - Fork 25.1k
Blazor state management updates #35873
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
Conversation
aspnetcore/blazor/state-management/persistent-component-state.md
Outdated
Show resolved
Hide resolved
aspnetcore/blazor/state-management/persistent-component-state.md
Outdated
Show resolved
Hide resolved
aspnetcore/blazor/state-management/persistent-component-state.md
Outdated
Show resolved
Hide resolved
aspnetcore/blazor/state-management/persistent-component-state.md
Outdated
Show resolved
Hide resolved
aspnetcore/blazor/state-management/prerendered-state-persistence.md
Outdated
Show resolved
Hide resolved
|
||
:::moniker-end | ||
|
||
Prerendering might be useful for other pages that don't use `localStorage` or `sessionStorage`. To retain prerendering, defer the loading operation until the browser is connected to the circuit. The following is an example for storing a counter value: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's good that we show that you can handle access storage in OnAfterRenderAsync. You could also detect whether the current render mode is interactive or not before accessing browser storage. I think that should work even in OnInitializedAsync.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Immediately after this merges, I'll open an issue on this because it's going to require an example. There's no time left to flesh this out right now 🏃.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few suggestions, but otherwise this looks good to me.
Co-authored-by: Daniel Roth <[email protected]>
This comment was marked as outdated.
This comment was marked as outdated.
@danroth27 @javiercn ... I just reacted to all of the feedback thus far with the two exceptions for follow-up issues:
|
This comment was marked as outdated.
This comment was marked as outdated.
Ok ... I think that fixes the 😈 . BTW @danroth27 ... WRT the three recommendations ...
That came about in a discussion with Mackinnon. This is a good time to change that sequence and which ones are marked as "Recommended" 👂. |
Co-authored-by: Daniel Roth <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we're out of time, let's go ahead and get this merged. We can follow up with any feedback from @javiercn later.
* *Recommended* for services outside of the shared framework: Create a custom service implementation for the service on the server. Use the service normally in interactive components of the `.Client` project. For a demonstration of this approach, see the example earlier in this section. | ||
|
||
Disabling enhanced navigation, which reduces performance but also avoids the problem of loading state with <xref:Microsoft.AspNetCore.Components.PersistentComponentState> for internal page requests, is covered in <xref:blazor/fundamentals/routing#enhanced-navigation-and-form-handling>. | ||
* Create a service abstraction and create implementations for the service in the `.Client` and server projects. Register the services in each project. Inject the custom service in the component. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Honestly, this is the most correct and flexible solution. One minor tweak:
* Create a service abstraction and create implementations for the service in the `.Client` and server projects. Register the services in each project. Inject the custom service in the component. | |
* Create a service abstraction and create implementations for the service in the `.Client` and server projects. Register the services in each project. Inject the custom service abstraction in the component. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I attempted to research it back, but things have moved around several times over the years. I see where Mackinnon reviewed these back when they were moved from the Render Modes article to this article, but he didn't comment on these recommendations. I don't see a discussion there. I think I did discuss this with him, and it might have been in an email. The simplest thing to do is just figure out what they should be for an update now/soon.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the available approaches are:
- Register the same service on both the server and client if it supports both.
- Make the service optional if it isn't always needed.
- Create a service abstraction and implement separate implementations for the server and client.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just reorganized ... possibly to the tune of what you wrote. I'll check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope ... that's not what I have. I need to re-order again. 😩
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok ... the order is closer to what you said, but you left out Mackinnon's "custom service implementation for the service on the server" approach, which I now have in the last position.
The example is the one over in the Environments article ...
The PR is updated now with what I think you want.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, that's the example where we suggest implementing and injecting an IWebAssemblyHostEnvironment service for the server, which is a bit confusing given that you're not actually running on WebAssembly. But it does work, so I guess that's fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When we reach the next issue on prerendering, this bit is going to have to be reorganized. It's a bit of a mess! 🙈😆 Each of these should be in a section with their examples. This is a case where content in another article should move, specifically the Environments example should move back to this article for sure.
Anyway ... no time right now. I have to flip over to Pre7 work.

— "I'll be back." - Cyberdyne Systems T-800 Series Model 101 (Arnold Schwarzenegger)
The Terminator 1984 Skydance Media
Co-authored-by: Daniel Roth <[email protected]>
…ithub.com/dotnet/AspNetCore.Docs into guardrex/blazor-circuit-state-persistence
Fixes #35717
Notes
[SupplyParameterFromPersistentComponentState]
attribute missing the word "parameter" in one part of the docs, which is corrected by this PR.I'm aware of the upcoming Pre7 name change for the
[SupplyParameterFromPersistentComponentState]
attribute, which will be taken care of on the upcoming Pre7 docs PR.Internal previews
Toggle expand/collapse