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

Misc HR updates #897

Merged
merged 5 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/Uno.Wasm.Bootstrap/Uno.Wasm.Bootstrap.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,13 @@
<Pack>true</Pack>
<PackagePath>tools</PackagePath>
<Visible>false</Visible>
<Visible>false</Visible>
</None>

<Content Include="$(NuGetPackageRoot)/newtonsoft.json/13.0.2/lib/netstandard2.0/*.dll">
<Pack>true</Pack>
<PackagePath>tools</PackagePath>
<Visible>false</Visible>
</Content>

</ItemGroup>

Expand All @@ -74,6 +79,7 @@
-->
<ItemGroup>
<_UnoTaskDependencies Include="$(NuGetPackageRoot)/mono.cecil/0.11.4/lib/netstandard2.0/*.dll" />
<_UnoTaskDependencies Include="$(NuGetPackageRoot)/newtonsoft.json/13.0.2/lib/netstandard2.0/*.dll" />
</ItemGroup>
<Copy
SourceFiles="@(_UnoTaskDependencies)"
Expand Down
26 changes: 9 additions & 17 deletions src/Uno.Wasm.Bootstrap/ts/Uno/WebAssembly/HotReloadSupport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ namespace Uno.WebAssembly.Bootstrap {

const webAppBasePath = this._unoConfig.environmentVariables["UNO_BOOTSTRAP_WEBAPP_BASE_PATH"];

// This assumes that the runtime includes the header as an env var:
// https://github.com/dotnet/runtime/blob/79a71fc750652191eba18e19b3f98492e882cb5f/src/mono/browser/runtime/loader/config.ts#L336
const browserToolsVariable = (<any>this._context).config.environmentVariables['ASPNETCORE-BROWSER-TOOLS'];

// Take the place of the internal .NET for WebAssembly APIs for metadata updates coming
// from the "BrowserLink" feature.
const bootstrapContext = this._context;

(function (Blazor) {
Blazor._internal = {
initialize: function () {
Expand All @@ -45,21 +47,11 @@ namespace Uno.WebAssembly.Bootstrap {

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

var hotreloadConfigResponse = await fetch(`/_framework/unohotreload`);

var modifiableAssemblies = hotreloadConfigResponse.headers.get('DOTNET-MODIFIABLE-ASSEMBLIES');
var aspnetCoreBrowserTools = hotreloadConfigResponse.headers.get('ASPNETCORE-BROWSER-TOOLS');

if (modifiableAssemblies) {
bootstrapContext.MONO.mono_wasm_setenv('DOTNET_MODIFIABLE_ASSEMBLIES', modifiableAssemblies);
}

// To uncomment once https://github.com/dotnet/aspnetcore/issues/37357#issuecomment-941237000 is released
// if (aspnetCoreBrowserTools == "true")
if (browserToolsVariable == "true")
{
try {
var m = <any>await import(`/_framework/blazor-hotreload.js`);
m.receiveHotReload();
await m.receiveHotReloadAsync();
}
catch (e) {
console.error(`Failed to apply initial metadata delta ${e}`);
Expand All @@ -72,15 +64,15 @@ namespace Uno.WebAssembly.Bootstrap {
return HotReloadSupport._getApplyUpdateCapabilitiesMethod();
},

applyHotReload: function (moduleId: any, metadataDelta: any, ilDelta: any, pdbDelta: any) {
applyHotReload: function (moduleId: any, metadataDelta: any, ilDelta: any, pdbDelta: any, updatedTypes: any) {
this.initialize();
return HotReloadSupport._applyHotReloadDeltaMethod(moduleId, metadataDelta, ilDelta, pdbDelta || "");
return HotReloadSupport._applyHotReloadDeltaMethod(moduleId, metadataDelta, ilDelta, pdbDelta || "", updatedTypes || []);
}
};
})((<any>window).Blazor || ((<any>window).Blazor = {}));

// Apply pending updates caused by a browser refresh
(<any>window).Blazor._internal.initialize(bootstrapContext.BINDING);
(<any>window).Blazor._internal.initialize();
await (<any>window).Blazor._internal.applyExisting();
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/Uno.Wasm.MetadataUpdater/WebAssemblyHotReload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
new UpdateDelta(),
};

[JSExport]

Check warning on line 31 in src/Uno.Wasm.MetadataUpdater/WebAssemblyHotReload.cs

View workflow job for this annotation

GitHub Actions / Build and Deploy Job

This call site is reachable on all platforms. 'JSExportAttribute' is only supported on: 'browser'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

Check warning on line 31 in src/Uno.Wasm.MetadataUpdater/WebAssemblyHotReload.cs

View workflow job for this annotation

GitHub Actions / Build and Deploy Job

This call site is reachable on all platforms. 'JSExportAttribute' is only supported on: 'browser'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)
internal static bool Initialize()
{
bool.TryParse(Environment.GetEnvironmentVariable("UNO_BOOTSTRAP_LOG_METADATA_UPDATES"), out _debugEnabled);
Expand Down Expand Up @@ -61,8 +61,8 @@
/// <summary>
/// For framework use only.
/// </summary>
[JSExport]

Check warning on line 64 in src/Uno.Wasm.MetadataUpdater/WebAssemblyHotReload.cs

View workflow job for this annotation

GitHub Actions / Build and Deploy Job

This call site is reachable on all platforms. 'JSExportAttribute' is only supported on: 'browser'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

Check warning on line 64 in src/Uno.Wasm.MetadataUpdater/WebAssemblyHotReload.cs

View workflow job for this annotation

GitHub Actions / Build and Deploy Job

This call site is reachable on all platforms. 'JSExportAttribute' is only supported on: 'browser'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)
public static void ApplyHotReloadDelta(string moduleIdString, string metadataDelta, string ilDeta, string pdbDelta)
public static void ApplyHotReloadDelta(string moduleIdString, string metadataDelta, string ilDeta, string pdbDelta, int[] updatedTypes)
{
if (_linkerEnabled)
{
Expand All @@ -84,6 +84,7 @@
_updateDeltas[0].MetadataDelta = Convert.FromBase64String(metadataDelta);
_updateDeltas[0].ILDelta = Convert.FromBase64String(ilDeta);
_updateDeltas[0].PdbBytes = Convert.FromBase64String(pdbDelta);
_updateDeltas[0].UpdatedTypes = updatedTypes;

_hotReloadAgent!.ApplyDeltas(_updateDeltas);
}
Expand All @@ -91,7 +92,7 @@
/// <summary>
/// For framework use only.
/// </summary>
[JSExport]

Check warning on line 95 in src/Uno.Wasm.MetadataUpdater/WebAssemblyHotReload.cs

View workflow job for this annotation

GitHub Actions / Build and Deploy Job

This call site is reachable on all platforms. 'JSExportAttribute' is only supported on: 'browser'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

Check warning on line 95 in src/Uno.Wasm.MetadataUpdater/WebAssemblyHotReload.cs

View workflow job for this annotation

GitHub Actions / Build and Deploy Job

This call site is reachable on all platforms. 'JSExportAttribute' is only supported on: 'browser'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)
public static string GetApplyUpdateCapabilities()
{
if (_debugEnabled)
Expand Down
10 changes: 10 additions & 0 deletions src/Uno.Wasm.Sample/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
using System.Globalization;
using System.Runtime.InteropServices.JavaScript;
using System.Threading.Tasks;
using System.Reflection.Metadata;
using Uno.Wasm.Sample;
using System.Linq;

[assembly: MetadataUpdateHandler(typeof(MyHandler))]

namespace Uno.Wasm.Sample
{
Expand Down Expand Up @@ -81,6 +86,11 @@ static void Main(string[] args)
}, null, 5000, 5000);
}
}
public static class MyHandler
{
internal static void ClearCache(Type[]? types) => Console.WriteLine("MyHandler.ClearCache");
internal static void UpdateApplication(Type[]? types) => Console.WriteLine($"MyHandler.UpdateApplication {types.Length} types: {string.Join(", ", types.Select(t => t.Name ))}");
}

#if NET7_0_OR_GREATER
public static partial class Imports
Expand Down
Loading