-
Notifications
You must be signed in to change notification settings - Fork 10.3k
[Blazor] Bring back stateful prerendering #15317
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
@javiercn : When we get stateful prerendering will this effect the lifecycle effects? Would be great to get rid of the "firstRender" flag. The fact that the component is rendered twice is a source of confusion for many beginners. |
@Postlagerkarte It should in most cases avoid the duplicated calls, but it's not unavoidable when the service is under heavy load, to keep the app available (similar guarantees as with re-connection) |
It would be cool if this can be integrated with client side blazor as well. Maybe the serialized state can be used to recreate the client state without executing the lifecycle events again which would be good because if we get the data from a REST service for example the client wouldn't need to call that service again since the server already did. |
It's not clear to me whether the solution proposed affects just server-side Blazor, or whether it's a pattern - as @Eirenarch appears to be suggesting - that would lend itself to rehydration via client-side WASM too. In any case, it'd be ideal if this also worked for server -> client prerendering scenarios, where a Blazor WebAssembly project is coupled with Blazor Server to allow generating the initial render as 'live' HTML, and then have client-side Blazor take over. Coming from React, the typical approach to handle the baton-passing from React SSR -> client-side is to serialize the server state in the resulting HTML, so the client can deserialize back to context/GraphQL cache/whatever else. The client can then avoid having to make redundant API calls (some of which could have side-effects, if called multiple times) for data it was already given on the initial dump. Since there's already the concept of statefulness in Blazor Server (and without knowing much about the internal details, so forgive this crude analysis), it seems to me that 'serializing' to HTML state could avoided in lieu of something like:
Again, I'm not familiar enough with the internals to know whether some of this is already baked in or which parts may be outstanding, but this IMO would put Blazor on par with JS frameworks that offer a (still clunky, but useable) methodology for gaining the benefits of SSR + the experience of SPA after the initial dump. I'd make this a first-class feature and put it front and centre, so developers really don't have to choose between Server or Client anymore -- it marries the best of both. |
Thanks for contacting us. |
@javiercn Should we close this, as the functionality is now subsumed into the pause/resume feature? |
It's something we could do "on top" as an optimization? It's still definitely hard to explain people why their OnInitializeAsync "runs twice", so I think we can still consider bringing this back with a fallback to pausing and resuming when "under heavy load". The reality is that this works for the majority of the apps for the majority of time, and now we have a reasonable strategy to support "availablity" under load. |
We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process. |
@mkArtakMSFT I saw that you are planning .net 8, it is worth getting interested in this problem. Also saw a similar thread already planned there. |
We're going to explore other techniques to enable this scenario. |
Considering the first issue the most important one, we could bring back a modified version of this feature as follows:
At this point the feature becomes an enhancement over the current experience, under regular load conditions the feature saves work and bandwidth on the server by avoiding things like requesting data from services multiple times or duplicating the amount of render requests, and under heavy traffic the feature simply falls-back to the current prerender mode.
Some supporting issues associated with this are #15266 #13607 #14977 #13448
The text was updated successfully, but these errors were encountered: