Skip to content
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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

maraf
Copy link
Member

@maraf maraf commented Mar 3, 2025

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

@maraf maraf added area-blazor Includes: Blazor, Razor Components feature-blazor-wasm This issue is related to and / or impacts Blazor WebAssembly labels Mar 3, 2025
@maraf maraf added this to the .NET 10 Planning milestone Mar 3, 2025
@maraf maraf self-assigned this Mar 3, 2025
@maraf maraf modified the milestones: .NET 10 Planning, 10.0-preview3 Mar 3, 2025
@maraf maraf changed the title [Blazor] Flow the environment from Server to WebAssembly through SSR marker [Blazor] Flow the WebAssembly settings from Server to client through SSR marker instead of headers on boot config Mar 5, 2025
@maraf maraf changed the title [Blazor] Flow the WebAssembly settings from Server to client through SSR marker instead of headers on boot config [Blazor] Flow the WebAssembly options from Server to client through SSR marker instead of headers on boot config Mar 5, 2025
@maraf maraf changed the title [Blazor] Flow the WebAssembly options from Server to client through SSR marker instead of headers on boot config [Blazor] Flow the WebAssembly options from Server to client through SSR marker Mar 5, 2025
@maraf maraf marked this pull request as ready for review March 5, 2025 13:41
@Copilot Copilot bot review requested due to automatic review settings March 5, 2025 13:41
@maraf maraf requested a review from a team as a code owner March 5, 2025 13:41

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>.*)$/;
@maraf maraf requested a review from a team March 6, 2025 08:51
Copy link
Member

@javiercn javiercn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

@pavelsavara
Copy link
Member

Could you please add example of generated HTML to the description, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-blazor Includes: Blazor, Razor Components feature-blazor-wasm This issue is related to and / or impacts Blazor WebAssembly
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants