Fix culture persistence to not have public API#67367
Conversation
There was a problem hiding this comment.
Pull request overview
This PR removes the unshipped public options/configuration surface for interactive WebAssembly culture persistence and replaces it with an internal options type driven by the Components:UseCultureFromServer configuration key.
Changes:
- Removes
WebAssemblyComponentsOptionsand theAddInteractiveWebAssemblyComponents(..., Action<WebAssemblyComponentsOptions>?)overload, leaving only the parameterlessAddInteractiveWebAssemblyComponents(). - Introduces internal
WebAssemblyComponentsServiceOptionsplus anIPostConfigureOptions<>to readComponents:UseCultureFromServer. - Updates the test server startup to set
Components:UseCultureFromServervia configuration, and updatesPublicAPI.Unshipped.txtaccordingly.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/Components/WebAssembly/Server/src/WebAssemblyRazorComponentsBuilderExtensions.cs | Removes the public overload and switches culture capture behavior to be driven by internal options/config. |
| src/Components/WebAssembly/Server/src/WebAssemblyComponentsServiceOptionsConfiguration.cs | Adds post-configure hook to read Components:UseCultureFromServer from configuration. |
| src/Components/WebAssembly/Server/src/WebAssemblyComponentsServiceOptions.cs | Adds internal options container (defaults UseCultureFromServer to true). |
| src/Components/WebAssembly/Server/src/WebAssemblyComponentsOptions.cs | Removes the (unshipped) public options type. |
| src/Components/WebAssembly/Server/src/PublicAPI.Unshipped.txt | Removes unshipped public API entries for the deleted options type and overload. |
| src/Components/test/testassets/Components.TestServer/RazorComponentEndpointsStartup.cs | Updates test server wiring to set the new configuration key instead of using the removed overload. |
| { | ||
| public void PostConfigure(string? name, WebAssemblyComponentsServiceOptions options) | ||
| { | ||
| var value = configuration["Components:UseCultureFromServer"]; |
There was a problem hiding this comment.
Where do we check if localization has been wired up?
There was a problem hiding this comment.
It's on by default and will work only if localization has been wired up.
There was a problem hiding this comment.
But what line of code checks that? From what I can see CaptureCurrentCulture() runs unconditionally regardless of localization being registered or not. I was expecting something that actually probes DI for localization.
There was a problem hiding this comment.
I will add it now to PR
| { | ||
| options.UseCultureFromServer = true; | ||
| } | ||
| if (string.Equals(value, "false", StringComparison.OrdinalIgnoreCase) || string.Equals(value, "0", StringComparison.OrdinalIgnoreCase)) |
There was a problem hiding this comment.
Since default value is true, isn't this "false" branch enough?
Fix culture persistence to not have public API
Summary
Reworks how WebAssembly culture persistence is configured so it no longer requires a public API surface. Instead of a public options class and a configuration callback overload, the behavior is now driven by the
Components:UseCultureFromServerconfiguration value.Changes
WebAssemblyComponentsOptionsclass and itsUseCultureFromServerproperty.AddInteractiveWebAssemblyComponents(this IRazorComponentsBuilder, Action<WebAssemblyComponentsOptions>?)overload. Only the parameterlessAddInteractiveWebAssemblyComponents()remains.WebAssemblyComponentsServiceOptionswith aUseCultureFromServerproperty (defaults totrue).WebAssemblyComponentsServiceOptionsConfiguration, anIPostConfigureOptions<WebAssemblyComponentsServiceOptions>that reads theComponents:UseCultureFromServerconfiguration value and binds it onto the options.PublicAPI.Unshipped.txtto drop the removed public API entries.Components.TestServerstartup to setComponents:UseCultureFromServervia configuration instead of using the removed callback overload.Details
CultureStateProvideris now always registered as a scoped service and always added as a persistent component state registration forRenderMode.InteractiveWebAssembly. Previously this registration was conditional onUseCultureFromServer.CaptureCurrentCulture()when the resolvedWebAssemblyComponentsServiceOptions.UseCultureFromServeristrue. This moves the decision from registration time to resolution time while preserving the same observable behavior (no culture capture when disabled).Components:UseCultureFromServeris set tofalse.Testing
RazorComponentEndpointsStartupnow toggles the behavior through theComponents:UseCultureFromServerconfiguration key ("true"/"false") based on the existingEnforceServerCultureOnClientsetting, exercising the new configuration path through the existing E2E culture scenarios.Breaking Changes
WebAssemblyComponentsOptionsand theAction<WebAssemblyComponentsOptions>?overload) is removed. These were unshipped, so no released package is affected. Consumers configuring this behavior should now set theComponents:UseCultureFromServerconfiguration value instead of passing an options callback.Fixes #66829