-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
[Blazor] Flow the WebAssembly options from Server to client through SSR marker #60714
base: main
Are you sure you want to change the base?
Conversation
and use it instead of relying on first component in blazor.web
…Assembly options comment
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.
PR Overview
This PR changes the mechanism for transmitting WebAssembly runtime settings by shifting from custom HTTP headers to embedding the settings within an SSR marker. Key changes include:
- Introducing a new WebAssemblySettingsEmitter that captures environment variables on the server.
- Modifying both server-side and JavaScript boot and discovery routines to process and propagate these settings via SSR markers.
- Removing legacy conventions for WebAssembly HTTP response header management.
Reviewed Changes
File | Description |
---|---|
src/Components/Endpoints/src/DependencyInjection/WebAssemblySettingsEmitter.cs | New emitter implementation to capture and expose WebAssembly environment settings. |
src/Components/Endpoints/src/Rendering/EndpointHtmlRenderer.Streaming.cs | Embeds the settings JSON into the SSR marker during rendering. |
src/Components/Web.JS/src/Services/ComponentDescriptorDiscovery.ts | Adds regex and discovery function for extracting WebAssembly options from SSR markers. |
src/Components/Endpoints/src/DependencyInjection/RazorComponentsServiceCollectionExtensions.cs | Registers the new WebAssemblySettingsEmitter in DI. |
src/Components/Web.JS/src/Boot.WebAssembly.Common.ts | Updates methods to accept and propagate WebAssembly options to the runtime. |
src/Components/Web.JS/src/Boot.WebAssembly.ts | Extracts and passes WebAssembly options to the startup routine. |
src/Components/Web.JS/src/Services/WebRootComponentManager.ts | Captures discovered WebAssembly options and passes them along during component registration. |
src/Components/Web.JS/src/Rendering/DomMerging/DomSync.ts | Updates the descriptor handler interface to include the WebAssembly options. |
src/Components/WebAssembly/Server/src/Builder/WebAssemblyRazorComponentsEndpointConventionBuilderExtensions.cs | Removes the legacy call to add Blazor WebAssembly conventions. |
src/Components/WebAssembly/Server/src/ComponentWebAssemblyConventions.cs | Legacy file removed as the functionality is now handled by the SSR marker. |
Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.
Comments suppressed due to low confidence (1)
src/Components/Web.JS/src/Services/ComponentDescriptorDiscovery.ts:18
- The regex for extracting WebAssembly options may be too permissive if the SSR marker comment format changes. Consider tightening the pattern (for example, by explicitly matching the opening '{') to ensure the 'options' group reliably captures a valid JSON object.
const blazorWebAssemblyOptionsCommentRegularExpression = /^\s*Blazor-WebAssembly:[^{]*(?<options>.*)$/;
src/Components/Endpoints/src/DependencyInjection/WebAssemblySettingsEmitter.cs
Show resolved
Hide resolved
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!
Could you please add example of generated HTML to the description, thanks! |
We won't be able to use HTTP headers after migration of boot config to ES module. The PR moves
EnvironmentName
,DOTNET_MODIFIABLE_ASSEMBLIES
and__ASPNETCORE_BROWSER_TOOLS
environment variables from custom HTTP headers on boot config request to SSR marker produced during server rendering.It doesn't affect standalone mode as there is no server to write these values to.
The prerendered comment looks like
<!--Blazor-WebAssembly:{"environmentName":"Development", "environmentVariables":{"DOTNET_MODIFIABLE_ASSEMBLIES": "true","__ASPNETCORE_BROWSER_TOOLS":"true}}-->
Contributes to #59456