[11.0 P5] Document client-side culture handling in Blazor#37215
Conversation
There was a problem hiding this comment.
Pull request overview
Adds documentation for a new Blazor Web App behavior in .NET 11+: client-side prerendering preserves the server culture by default, and how to opt out.
Changes:
- Document how server culture is persisted/applied for client-side prerendering in a Blazor Web App (monikered for
>= aspnetcore-11.0). - Show how to disable culture propagation with
UseCultureFromServer.
|
|
||
| ## Client-side prerendering in a Blazor Web App preserves the server's culture | ||
|
|
||
| By default, client-side prerendering on the server (`.Client` project in a Blazor Web App) persists the server's <xref:System.Globalization.CultureInfo.CurrentCulture> and <xref:System.Globalization.CultureInfo.CurrentUICulture> into component state and applies them on the client before satellite assemblies load. This ensures that the client renders with the same culture as the server. |
There was a problem hiding this comment.
Prerendering will always take culture from server not dependent if users set UseCultureFromServer or not. The problem was with difference in culture in prerendering and in running interactive client. Right now we just remember that state and apply it when interactivity starts on client.
There was a problem hiding this comment.
I think I understand if you're referring to the last line. It came from the end of the second sentence in the following PR remark ...
During server-side prerendering, the current thread's culture (CurrentCulture and CurrentUICulture) is captured and persisted via the PersistentComponentState infrastructure. After hydration on the WebAssembly client, the stored culture is applied before satellite assemblies are loaded, ensuring the client renders with the same culture as the server.
Let's remove that last sentence because I think the rest of it is clear.
UPDATE: Done! 👍
Co-authored-by: Luke Latham <1622880+guardrex@users.noreply.github.com>
Fixes #37214
Daria ... I'll added the blurb on this to the ASP.NET Core release notes on #37206, which is the PR that focuses on QuickGrid updates.
Note that this content is phrased a bit differently in Blazor docs than how Copilot phrased it in the .NET Core release notes: The Blazor docs typically only use "Blazor WebAssembly" to discuss standalone Blazor WebAssembly. When referring to the Blazor WebAssembly rendering of a BWA, the docs usually use language about the CSR of a BWA and mention the
.Clientproject. You'll see on the diff how I've normally handled it. I'm 👂 for your feedback on it.I'm not sure if the section Dynamically set the culture in a Blazor Web App by user preference requires changes. That approach is focused on using local storage to save/load the culture, and the cookie is updated on the server after a client-side culture change is made. You should look tho to see if you think any changes are needed. Since it currently uses a controller on the backend, I just opened Swap a Minimal API for the CultureController (
dotnet/AspNetCore.Docs#37216) to convert that part to a Minimal API. I'll get on that very soon! 🏃♂️Internal previews