-
Notifications
You must be signed in to change notification settings - Fork 1.1k
[wasm] General HotReload agent for WebAssembly in browser #49800
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
Conversation
Thanks for your PR, @@maraf. |
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.
Pull Request Overview
This PR extracts the HotReload agent from Blazor to create a general-purpose HotReload capability for WebAssembly browser scenarios. The goal is to enable HotReload functionality in non-Blazor WebAssembly applications.
Key changes include:
- Adding implicit HotReload package reference in WasmSDK for .NET 10+ projects
- Creating a new WebAssembly-specific HotReload agent that can work independently of Blazor
- Implementing JavaScript interop for runtime configuration and delta application
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/WasmSdk/Sdk/Sdk.targets | Adds implicit package reference for HotReload with conditional enablement logic |
src/BuiltInTools/dotnet-watch.slnf | Includes new HotReload WebAssembly project in solution filter |
wwwroot/Microsoft.DotNet.HotReload.WebAssembly.Browser.lib.module.js | JavaScript module for runtime configuration and Blazor API compatibility |
WebAssemblyHotReload.cs | Core C# implementation handling delta application and HTTP communication |
Microsoft.DotNet.HotReload.WebAssembly.Browser.csproj | Project file for new HotReload package |
sdk.slnx | Adds new project to main solution |
Comments suppressed due to low confidence (2)
src/BuiltInTools/HotReloadAgent.WebAssembly.Browser/WebAssemblyHotReload.cs:109
- [nitpick] The variable name 'i' is not descriptive. Consider renaming it to 'updateIndex' or 'currentUpdate' to improve code readability.
var i = 1;
src/BuiltInTools/HotReloadAgent.WebAssembly.Browser/WebAssemblyHotReload.cs:147
- The variable name 'jsonContext' does not follow C# naming conventions for private static readonly fields. It should be 's_jsonContext' to match the pattern used elsewhere in this class.
private static readonly WebAssemblyHotReloadJsonSerializerContext jsonContext = new(new(JsonSerializerDefaults.Web));
src/BuiltInTools/HotReloadAgent.WebAssembly.Browser/WebAssemblyHotReload.cs
Outdated
Show resolved
Hide resolved
…yHotReload.cs Co-authored-by: Copilot <[email protected]>
...ols/HotReloadAgent.WebAssembly.Browser/Microsoft.DotNet.HotReload.WebAssembly.Browser.csproj
Show resolved
Hide resolved
src/BuiltInTools/HotReloadAgent.WebAssembly.Browser/WebAssemblyHotReload.cs
Outdated
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.
LGTM. Someone should review the WasmSdk change. Looks reasonable but I can't tell if there are any undesirable side effects.
...ols/HotReloadAgent.WebAssembly.Browser/Microsoft.DotNet.HotReload.WebAssembly.Browser.csproj
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.
Some small suggestions, but overall looks good
…ferencing project
/ba-g Container failures are unrelated |
Extract HotReload agent from Blazor to a general purpose HotReload for WebAssembly in browser scenarios.
The goal is to enable HotReload in non-Blazor scenarios.
The package is implicitly referenced by WasmSDK and can be turned off with
WasmEnableHotReload=false
. We are always referencing "current" version and for downlevel we need to multitarget.The package contains a module that is recognized by WasmSDK and automatically loaded. The module then instructs Mono runtime that HotReload is enabled and provides callbacks migrated from Blazor internal JS API that are used by
aspnetcore-browser-refresh.js
. Before the built-in HotReload in Blazor gets removed, the module also disables it.Migration from Blazor
WebAssemblyHotReload.cs
-> aspnetcore/WebAssemblyHotReload.csMicrosoft.DotNet.HotReload.WebAssembly.Browser.lib.module.js
-> aspnetcore/Boot.WebAssembly.Common.tsContributes to dotnet/aspnetcore#61272
Related to dotnet/aspnetcore#62735