Skip to content

Commit

Permalink
Hot Reload agent improvements
Browse files Browse the repository at this point in the history
Refactor agent code so that it can be shared with dotnet-watch implementation via a shared project.

Add new API applyHotReloadDeltas to apply updates.
  • Loading branch information
tmat committed Nov 14, 2024
1 parent be19faf commit f791377
Show file tree
Hide file tree
Showing 14 changed files with 528 additions and 253 deletions.
2 changes: 1 addition & 1 deletion src/Components/Web.JS/dist/Release/blazor.server.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/Components/Web.JS/dist/Release/blazor.web.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/Components/Web.JS/dist/Release/blazor.webassembly.js

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions src/Components/Web.JS/src/Boot.WebAssembly.Common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,15 @@ async function startCore(components: RootComponentManager<WebAssemblyComponentDe
}
});

// obsolete:
Blazor._internal.applyHotReload = (id: string, metadataDelta: string, ilDelta: string, pdbDelta: string | undefined, updatedTypes?: number[]) => {
dispatcher.invokeDotNetStaticMethod('Microsoft.AspNetCore.Components.WebAssembly', 'ApplyHotReloadDelta', id, metadataDelta, ilDelta, pdbDelta, updatedTypes ?? null);
};

Blazor._internal.applyHotReloadDeltas = (deltas: { moduleId: string, metadataDelta: string, ilDelta: string, pdbDelta: string, updatedTypes: number[] }[], loggingLevel: number) => {
return dispatcher.invokeDotNetStaticMethod('Microsoft.AspNetCore.Components.WebAssembly', 'ApplyHotReloadDeltas', deltas, loggingLevel);
};

Blazor._internal.getApplyUpdateCapabilities = () => dispatcher.invokeDotNetStaticMethod('Microsoft.AspNetCore.Components.WebAssembly', 'GetApplyUpdateCapabilities');

// Configure JS interop
Expand Down
4 changes: 4 additions & 0 deletions src/Components/Web.JS/src/GlobalExports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,11 @@ export interface IBlazor {
}

// APIs invoked by hot reload

// obsolete:
applyHotReload?: (id: string, metadataDelta: string, ilDelta: string, pdbDelta: string | undefined, updatedTypes?: number[]) => void;

applyHotReloadDeltas?: (deltas: { moduleId: string, metadataDelta: string, ilDelta: string, pdbDelta: string, updatedTypes: number[] }[], loggingLevel: number) => {message: string, severity: number}[];
getApplyUpdateCapabilities?: () => string;
hotReloadApplied?: () => void;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace Microsoft.Extensions.HotReload;

internal enum AgentMessageSeverity : byte
{
Verbose = 0,
Warning = 1,
Error = 2,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Linq;

namespace Microsoft.Extensions.HotReload;

internal sealed class AgentReporter
{
private readonly List<(string message, AgentMessageSeverity severity)> _log = [];

public void Report(string message, AgentMessageSeverity severity)
{
_log.Add((message, severity));
}

public IReadOnlyCollection<(string message, AgentMessageSeverity severity)> GetAndClearLogEntries(ResponseLoggingLevel level)
{
lock (_log)
{
var filteredLog = (level != ResponseLoggingLevel.Verbose)
? _log.Where(static entry => entry.severity != AgentMessageSeverity.Verbose)
: _log;

var log = filteredLog.ToArray();
_log.Clear();
return log;
}
}
}
Loading

0 comments on commit f791377

Please sign in to comment.