Skip to content

Commit 278fcf7

Browse files
committed
fix: Adjust HR invocations to internal APIs
Use existing envvars to detect HR, use async initial HR for blazor-hotreload.js
1 parent 944878d commit 278fcf7

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

src/Uno.Wasm.Bootstrap/ts/Uno/WebAssembly/HotReloadSupport.ts

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ namespace Uno.WebAssembly.Bootstrap {
3333

3434
// Take the place of the internal .NET for WebAssembly APIs for metadata updates coming
3535
// from the "BrowserLink" feature.
36-
const bootstrapContext = this._context;
36+
const browserToolsVariable = (<any>this._context).config.environmentVariables['ASPNETCORE-BROWSER-TOOLS'];
3737

3838
(function (Blazor) {
3939
Blazor._internal = {
@@ -45,21 +45,11 @@ namespace Uno.WebAssembly.Bootstrap {
4545

4646
applyExisting: async function (): Promise<void> {
4747

48-
var hotreloadConfigResponse = await fetch(`/_framework/unohotreload`);
49-
50-
var modifiableAssemblies = hotreloadConfigResponse.headers.get('DOTNET-MODIFIABLE-ASSEMBLIES');
51-
var aspnetCoreBrowserTools = hotreloadConfigResponse.headers.get('ASPNETCORE-BROWSER-TOOLS');
52-
53-
if (modifiableAssemblies) {
54-
bootstrapContext.MONO.mono_wasm_setenv('DOTNET_MODIFIABLE_ASSEMBLIES', modifiableAssemblies);
55-
}
56-
57-
// To uncomment once https://github.com/dotnet/aspnetcore/issues/37357#issuecomment-941237000 is released
58-
// if (aspnetCoreBrowserTools == "true")
48+
if (browserToolsVariable == "true")
5949
{
6050
try {
6151
var m = <any>await import(`/_framework/blazor-hotreload.js`);
62-
m.receiveHotReload();
52+
await m.receiveHotReloadAsync();
6353
}
6454
catch (e) {
6555
console.error(`Failed to apply initial metadata delta ${e}`);
@@ -80,7 +70,7 @@ namespace Uno.WebAssembly.Bootstrap {
8070
})((<any>window).Blazor || ((<any>window).Blazor = {}));
8171

8272
// Apply pending updates caused by a browser refresh
83-
(<any>window).Blazor._internal.initialize(bootstrapContext.BINDING);
73+
(<any>window).Blazor._internal.initialize();
8474
await (<any>window).Blazor._internal.applyExisting();
8575
}
8676
}

src/Uno.Wasm.Sample/Program.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@
2121
using System.Globalization;
2222
using System.Runtime.InteropServices.JavaScript;
2323
using System.Threading.Tasks;
24+
using System.Reflection.Metadata;
25+
using Uno.Wasm.Sample;
26+
using System.Linq;
27+
28+
[assembly: MetadataUpdateHandler(typeof(MyHandler))]
2429

2530
namespace Uno.Wasm.Sample
2631
{
@@ -81,6 +86,11 @@ static void Main(string[] args)
8186
}, null, 5000, 5000);
8287
}
8388
}
89+
public static class MyHandler
90+
{
91+
internal static void ClearCache(Type[]? types) => Console.WriteLine("MyHandler.ClearCache");
92+
internal static void UpdateApplication(Type[]? types) => Console.WriteLine($"MyHandler.UpdateApplication {types.Length} types: {string.Join(", ", types.Select(t => t.Name ))}");
93+
}
8494

8595
#if NET7_0_OR_GREATER
8696
public static partial class Imports

0 commit comments

Comments
 (0)