-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Added Culture persistence between Client and Server #63144
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
base: main
Are you sure you want to change the base?
Added Culture persistence between Client and Server #63144
Conversation
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.
Pull Request Overview
This pull request introduces a culture persistence mechanism for Blazor WebAssembly applications, allowing server-side culture settings to be maintained on the client after hydration. The main purpose is to ensure consistent localization between server prerendering and client-side execution.
- Adds
CultureStateProvider
class to capture and restore culture information across server-client transitions - Integrates culture restoration into the WebAssembly host startup sequence after state restoration
- Provides
EnforceServerCultureOnClient
extension method to enable this feature opt-in
Reviewed Changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
src/Components/Shared/src/CultureStateProvider.cs |
New class that captures current culture during prerendering and applies it on the client |
src/Components/WebAssembly/Server/src/WebAssemblyRazorComponentsBuilderExtensions.cs |
Adds EnforceServerCultureOnClient extension method for configuration |
src/Components/WebAssembly/WebAssembly/src/Hosting/WebAssemblyHost.cs |
Integrates culture restoration into startup flow after state restoration |
src/Components/WebAssembly/WebAssembly/src/Hosting/WebAssemblyHostBuilder.cs |
Registers CultureStateProvider for WebAssembly projects |
src/Components/test/E2ETest/ServerRenderingTests/InteractivityTest.cs |
E2E tests verifying culture persistence behavior |
Various project files | Adds shared source references for CultureStateProvider |
Comments suppressed due to low confidence (3)
src/Components/Shared/src/CultureStateProvider.cs:5
- The CultureStateProvider class should be in a more appropriate namespace. Since it deals with culture persistence and not forms, it should be in Microsoft.AspNetCore.Components.Web or Microsoft.AspNetCore.Components namespace instead of Microsoft.AspNetCore.Components.Forms.
namespace Microsoft.AspNetCore.Components.Forms;
src/Components/WebAssembly/WebAssembly/src/Hosting/WebAssemblyHost.cs:5
- This using statement is inconsistent with the actual namespace where CultureStateProvider should be located. If the class is moved to the correct namespace, this using statement should be updated accordingly.
using Microsoft.AspNetCore.Components.Forms;
src/Components/WebAssembly/Server/src/WebAssemblyRazorComponentsBuilderExtensions.cs:10
- This using statement is inconsistent with the actual namespace where CultureStateProvider should be located. If the class is moved to the correct namespace, this using statement should be updated accordingly.
using Microsoft.AspNetCore.Components.Forms;
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.
Looks great.
Mainly we will have to discuss the naming on API review
Added Culture persistence between Client and Server
Description
This pull request introduces a new mechanism to persist and enforce the server-side culture on the client in Blazor WebAssembly applications. The main feature is the addition of the
CultureStateProvider
, which captures the current culture during server prerendering and applies it on the client after hydration.Changes:
CultureStateProvider
class, which captures the current thread's culture and UI culture for persistence and can reapply them on the client side after hydration.CultureStateProvider
in relevant project files so it is available for both server and WebAssembly projects.EnforceServerCultureOnClient
extension method toIRazorComponentsBuilder
, which registers and persists theCultureStateProvider
for interactive WebAssembly render mode.WebAssemblyHost
so that, after restoring persisted state, the stored culture is applied (if available) before loading culture-specific resources.EnforceServerCultureOnClient
to the unshipped PublicAPI.Fixes #26941