[wasm] HotReload script consolidation#54142
Draft
maraf wants to merge 3 commits into
Draft
Conversation
…ingStream For Blazor WebAssembly, the hot reload WebSocket communication logic from WebSocketScriptInjection.js is now embedded directly into the lib.module.js JavaScript initializer. This eliminates the need for ScriptInjectingStream to inject a <script> tag into HTML responses for WASM scenarios. Changes: - Add /_framework/browser-refresh-config JSON endpoint that returns the WebSocket URL and server key (read from existing env vars) - Port all WebSocket handlers from WebSocketScriptInjection.js into lib.module.js (reload, CSS updates, managed code updates, diagnostics, capabilities, browser refresh, toast notifications) - Maintain backward compatibility: if config endpoint is unavailable, falls back to detecting the injected script tag (hosted scenarios) - Sentinel-based double-connection prevention between lib.module.js and the injected script, with fallback clearing on connection failure - Add tests for the new config endpoint Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
For WebAssembly apps targeting .NET 11+, the lib.module.js handles the browser refresh WebSocket connection directly, making the injected <script> tag redundant. This change: - Adds ASPNETCORE_AUTO_RELOAD_SUPPRESS_SCRIPT_INJECTION env var - WebAssemblyHotReloadClient sets it for .NET 11+ projects - BrowserRefreshMiddleware skips HTML response interception when set - Avoids the overhead of ScriptInjectingStream for WASM apps Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
|
Thanks for your PR, @@maraf. |
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Consolidates hot reload WebSocket communication for Blazor WebAssembly by embedding the logic from
WebSocketScriptInjection.jsdirectly into the WASMlib.module.jsJavaScript initializer. This eliminates the need forScriptInjectingStreamto inject a<script>tag into HTML responses for .NET 11+ WASM apps.Changes
New config endpoint (
/_framework/browser-refresh-config){webSocketUrls, serverKey}read from existing middleware env varslib.module.jsto discover WebSocket connection parameters without script injectionEmbed WebSocket logic into
lib.module.jsWebSocketScriptInjection.js: reload, wait, CSS updates, managed code updates, diagnostics, capabilities, browser refresh, toast notificationsonRuntimeConfigLoaded; establishes WebSocket inonRuntimeReadyDisable script injection for .NET 11+ WASM
ASPNETCORE_AUTO_RELOAD_SUPPRESS_SCRIPT_INJECTIONenv varWebAssemblyHotReloadClientsets it when project TFM >= 11.0BrowserRefreshMiddlewareskips HTML response interception when setScriptInjectingStreamfor WASM appsBackward compatibility
ScriptInjectingStream.csandWebSocketScriptInjection.jsremain untouched for non-WASM and pre-.NET 11 scenarios_dotnet_watch_ws_injected) ensures only one WebSocket connection when both mechanisms are presentlib.module.jsstill enables Blazor hooks via injected script tag detectionTesting