Skip to content

Enable Gateway-native hot reload for standalone Blazor WebAssembly - #56071

Closed
javiercn wants to merge 2 commits into
mainfrom
javiercn-implement-gateway-hot-reload
Closed

javiercn wants to merge 2 commits into
mainfrom
javiercn-implement-gateway-hot-reload

Conversation

@javiercn

@javiercn javiercn commented Sep 1, 2026

Copy link
Copy Markdown
Member

Summary

  • route .NET 11+ standalone Blazor WebAssembly browser tooling through Blazor Gateway instead of BrowserRefresh startup-hook/hosting-startup injection
  • add versioned provider HTTP/WebSocket endpoints, authenticated browser connections, and generation-scoped replay owned by dotnet watch
  • split provider discovery/runtime setup from the browser-tools client module and keep both modules build-only
  • preserve legacy hosting-startup behavior for hosted, older-target-framework, and other compatible app models

Manual validation

Validated with a real standalone net11.0 Blazor WebAssembly app and the locally built SDK/watch tool:

  • Gateway proxied session.json, replay, cache-clearing, and WebSocket upgrade requests through the stable root route, including with Gateway__PathBase=/base
  • Razor/C# edits rendered live without restart
  • CSS changes cleared cache and replaced only the matching stylesheet with a nonce URL
  • reload and a second browser tab replayed the current generation; subsequent edits reached both tabs
  • unauthenticated WebSocket upgrade was rejected with HTTP 400
  • Gateway launch omitted DOTNET_STARTUP_HOOKS, ASPNETCORE_HOSTINGSTARTUPASSEMBLIES, launch-time DOTNET_MODIFIABLE_ASSEMBLIES, and BrowserRefresh variables
  • plain dotnet run remained functional and inactive after the bounded provider probe returned 404

Tests

  • full SDK/redist build
  • 23 provider/router/store/client tests
  • 23 watch app-model/browser-refresh/Kestrel tests
  • 1 WASM build-only asset test
  • 4 affected WASM static-web-asset baseline tests
  • node --check for both browser modules
  • git diff --check

Design note

The browser establishes and buffers its live WebSocket before replay completes, then activates live processing after replay. This preserves replay-before-live ordering while closing the missed-update window. Browser-tools traffic intentionally remains on the reserved root route when the application has a Gateway path base.

Copilot AI lite review requested due to automatic review settings September 1, 2026 14:45
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 2 pipeline(s).
1 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Pull request overview

Routes .NET 11+ standalone Blazor WebAssembly dotnet watch browser tooling through Gateway-native endpoints (HTTP + WebSocket) instead of relying on hosting-startup/startup-hook injection, while keeping legacy behavior for other app models/TFMs.

Changes:

  • Add a versioned browser-tools protocol surface (session.json, updates/{generation}.json, clear-cache, connect) with generation-scoped update replay and authenticated WebSocket connections.
  • Introduce launch-configuration abstraction to switch between legacy hosting-startup injection and Gateway/YARP proxy configuration based on the app model/TFM.
  • Extend WASM SDK/static-web-asset baselines and tests to ensure the new browser-tools JS module is build-only (not published).
File summaries
File Description
test/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/WasmJsModulesIntegrationTests.cs Adds an integration test ensuring the BrowserTools JS module is build-only and excluded from publish outputs.
test/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/StaticWebAssetsBaselines/StaticWebAssets_BuildMinimal_Works.Build.staticwebassets.json Updates baseline to include BrowserTools module assets/endpoints in build manifest.
test/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/StaticWebAssetsBaselines/StaticWebAssets_BuildMinimal_Works.Build.files.json Updates baseline file list to include BrowserTools module outputs.
test/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/StaticWebAssetsBaselines/StaticWebAssets_Build_Hosted_Works.Build.staticwebassets.json Updates hosted baseline to include BrowserTools module assets/endpoints.
test/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/StaticWebAssetsBaselines/JSModules_ManifestIncludesModuleTargetPaths.Build.staticwebassets.json Updates JS module baseline to include BrowserTools module entries.
test/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/StaticWebAssetsBaselines/Build_DoesNotGenerateManifestJson_IncludesJSModulesOnBlazorBootJsonManifest.Build.staticwebassets.json Updates baseline to include BrowserTools module in the build manifest shape used by this scenario.
test/Microsoft.Extensions.DotNetDeltaApplier.Tests/WebAssemblyHotReloadClientTests.cs Adds tests validating replay-enabled behavior vs legacy behavior when no browser is connected.
test/Microsoft.Extensions.DotNetDeltaApplier.Tests/BrowserToolsUpdateStoreTests.cs Adds unit tests for generation/update ordering and reset semantics of the replay store.
test/Microsoft.Extensions.DotNetDeltaApplier.Tests/BrowserToolsEndpointRouterTests.cs Adds unit tests for the new browser-tools endpoint router behavior and error handling.
test/dotnet-watch.Tests/Browser/BrowserRefreshServerTests.cs Adds coverage for inserting BrowserRefresh-related env vars into an existing environment dictionary.
test/dotnet-watch.Tests/Browser/BlazorWebAssemblyAppModelTests.cs Adds coverage for Gateway vs hosting-startup launch configuration selection for net11+ standalone WASM.
src/WasmSdk/Sdk/Sdk.targets Copies and registers the new BrowserTools JS module into the hotreload intermediate/static-web-assets pipeline.
src/Dotnet.Watch/Watch/AppModels/WebApplicationAppModel.cs Adds launch-configurator plumbing and passes generation/replay parameters into the WASM hot reload client.
src/Dotnet.Watch/Watch/AppModels/BlazorWebAssemblyAppModel.cs Switches net11+ standalone WASM to Gateway proxy launch config and enables replay in the WASM client.
src/Dotnet.Watch/HotReloadClient/Web/WebServerHost.cs Splits WebSocket vs HTTP endpoint exposure to support Gateway proxy addressing.
src/Dotnet.Watch/HotReloadClient/Web/WebAssemblyHotReloadClient.cs Adds generation ID + optional replay storage and includes generation ID in managed-update messages.
src/Dotnet.Watch/HotReloadClient/Web/KestrelWebSocketServer.cs Exposes both WebSocket URLs and underlying HTTP URLs from Kestrel.
src/Dotnet.Watch/HotReloadClient/Web/IBrowserToolsLaunchConfigurator.cs Introduces a launch-environment configurator interface and feature flags.
src/Dotnet.Watch/HotReloadClient/Web/HostingStartupBrowserToolsLaunchConfigurator.cs Implements legacy hosting-startup/startup-hook environment configuration behind the new abstraction.
src/Dotnet.Watch/HotReloadClient/Web/GatewayProxyBrowserToolsLaunchConfigurator.cs Implements Gateway/YARP proxy environment configuration for browser-tools traffic.
src/Dotnet.Watch/HotReloadClient/Web/BrowserToolsUpdateStore.cs Adds a thread-safe generation-scoped replay store for managed-update batches.
src/Dotnet.Watch/HotReloadClient/Web/BrowserToolsProtocol.cs Defines protocol constants and reserved route prefix for browser-tools endpoints.
src/Dotnet.Watch/HotReloadClient/Web/BrowserToolsEndpointRouter.cs Adds HTTP routing for browser-tools endpoints and authenticated WebSocket connect handling.
src/Dotnet.Watch/HotReloadClient/Web/BrowserRefreshServer.cs Routes requests either to browser-tools HTTP endpoints or legacy WebSocket acceptance.
src/Dotnet.Watch/HotReloadClient/Web/AbstractBrowserRefreshServer.cs Centralizes WebSocket acceptance logic and exposes data needed by launch configurators/router.
src/Dotnet.Watch/HotReloadClient/HotReloadClients.cs Switches launch env configuration to use the new launch configurator.
src/Dotnet.Watch/HotReloadAgent.WebAssembly.Browser/wwwroot/Microsoft.DotNet.HotReload.WebAssembly.BrowserTools.lib.module.js Adds the new browser-tools JS module (auth + replay buffering + CSS swap + live update processing).
src/Dotnet.Watch/HotReloadAgent.WebAssembly.Browser/wwwroot/Microsoft.DotNet.HotReload.WebAssembly.Browser.lib.module.js Adds provider discovery/replay activation and legacy fallback logic in the existing WASM loader module.
src/Dotnet.Watch/HotReloadAgent.WebAssembly.Browser/WebAssemblyHotReload.cs Adds an initializer variant that skips applying previous deltas (Gateway replay handles it).
src/Dotnet.Watch/dotnet-watch/Watch/DotNetWatcher.cs Adjusts environment building per-iteration and uses the new configurator for BrowserRefresh-only setup.
src/Dotnet.Watch/AGENTS.md Updates contributor/agent guidance for the new Gateway-native WASM hot reload path.
eng/Signing.props Adds signing metadata for the new BrowserTools JS module.
Review details
  • Files reviewed: 32/32 changed files
  • Comments generated: 1
  • Review effort level: Lite

Comment on lines +8 to +11
using System;
using System.Net;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
{
}

public WebServerHost(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This can be primary constructor.

AbstractBrowserRefreshServer? browserRefreshServer,
bool useRefreshServerToApplyStaticAssets) : IDisposable
bool useRefreshServerToApplyStaticAssets,
IBrowserToolsLaunchConfigurator? browserToolsLaunchConfigurator = null) : IDisposable

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Make this non-optional, so that we don't forget to pass it in all call sites that should have it.

Move standalone net11 Blazor WASM activation to a watch-owned provider reached through Blazor Gateway's existing reverse proxy.

Behavior: changed: standalone net11 WASM discovers provider-owned browser tooling without BrowserRefresh startup injection

State: builds; regression coverage follows in the next commit

Review hint: focus on provider discovery, generation replay, and the fixed Gateway route; the remainder is wiring

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 49a13c60-1d66-4321-bfdb-01275ead89d6
Add provider endpoint, replay-store, launch-selection, and build-only WASM asset coverage for the Gateway-native implementation.

Behavior: preserved

State: complete for PR #56071

Review hint: generated Static Web Assets baseline additions represent the two build-only hot reload modules

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 49a13c60-1d66-4321-bfdb-01275ead89d6
@javiercn
javiercn force-pushed the javiercn-implement-gateway-hot-reload branch from e0f0b2e to 8792886 Compare September 2, 2026 10:32
@javiercn
javiercn requested a review from a team as a code owner September 2, 2026 10:32
javiercn added a commit that referenced this pull request Sep 8, 2026
Add provider endpoint, replay-store, launch-selection, and build-only WASM asset coverage for the Gateway-native implementation.

Behavior: preserved

State: complete for PR #56071

Review hint: generated Static Web Assets baseline additions represent the two build-only hot reload modules

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 49a13c60-1d66-4321-bfdb-01275ead89d6
javiercn added a commit that referenced this pull request Sep 18, 2026
Add provider endpoint, replay-store, launch-selection, and build-only WASM asset coverage for the Gateway-native implementation.

Behavior: preserved

State: complete for PR #56071

Review hint: generated Static Web Assets baseline additions represent the two build-only hot reload modules

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 49a13c60-1d66-4321-bfdb-01275ead89d6
@github-actions

github-actions Bot commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

Due to lack of recent activity, this PR has been labeled as 'Stale'. It will be closed if no further activity occurs within 7 more days. Any new comment will remove the label.

@github-actions github-actions Bot added the stale label Nov 1, 2026
@github-actions github-actions Bot closed this Nov 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants