diff --git a/src/Components/Web.JS/src/Boot.WebAssembly.Common.ts b/src/Components/Web.JS/src/Boot.WebAssembly.Common.ts index a5bb02d5b80d..4240be05c307 100644 --- a/src/Components/Web.JS/src/Boot.WebAssembly.Common.ts +++ b/src/Components/Web.JS/src/Boot.WebAssembly.Common.ts @@ -98,17 +98,6 @@ async function startCore(components: RootComponentManager { - 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 Blazor._internal.invokeJSJson = invokeJSJson; Blazor._internal.endInvokeDotNetFromJS = endInvokeDotNetFromJS; diff --git a/src/Components/Web.JS/src/GlobalExports.ts b/src/Components/Web.JS/src/GlobalExports.ts index ad868dcb58c4..89d5d5535fd5 100644 --- a/src/Components/Web.JS/src/GlobalExports.ts +++ b/src/Components/Web.JS/src/GlobalExports.ts @@ -92,11 +92,6 @@ 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; } } diff --git a/src/Components/WebAssembly/WebAssembly/src/Hosting/WebAssemblyHost.cs b/src/Components/WebAssembly/WebAssembly/src/Hosting/WebAssemblyHost.cs index bd4c88059729..5cb848752449 100644 --- a/src/Components/WebAssembly/WebAssembly/src/Hosting/WebAssemblyHost.cs +++ b/src/Components/WebAssembly/WebAssembly/src/Hosting/WebAssemblyHost.cs @@ -2,11 +2,9 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Diagnostics.CodeAnalysis; -using System.Reflection.Metadata; using Microsoft.AspNetCore.Components.Infrastructure; using Microsoft.AspNetCore.Components.Web; using Microsoft.AspNetCore.Components.Web.Infrastructure; -using Microsoft.AspNetCore.Components.WebAssembly.HotReload; using Microsoft.AspNetCore.Components.WebAssembly.Infrastructure; using Microsoft.AspNetCore.Components.WebAssembly.Rendering; using Microsoft.AspNetCore.Components.WebAssembly.Services; @@ -139,11 +137,6 @@ internal async Task RunAsyncCore(CancellationToken cancellationToken, WebAssembl manager.SetPlatformRenderMode(RenderMode.InteractiveWebAssembly); await manager.RestoreStateAsync(store); - if (MetadataUpdater.IsSupported && Environment.GetEnvironmentVariable("__BLAZOR_WEBASSEMBLY_LEGACY_HOTRELOAD") != "false") - { - await WebAssemblyHotReload.InitializeAsync(); - } - var tcs = new TaskCompletionSource(); using (cancellationToken.Register(() => tcs.TrySetResult())) { diff --git a/src/Components/WebAssembly/WebAssembly/src/HotReload/WebAssemblyHotReload.cs b/src/Components/WebAssembly/WebAssembly/src/HotReload/WebAssemblyHotReload.cs deleted file mode 100644 index 907e3042aa7f..000000000000 --- a/src/Components/WebAssembly/WebAssembly/src/HotReload/WebAssemblyHotReload.cs +++ /dev/null @@ -1,165 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System.ComponentModel; -using System.Diagnostics.CodeAnalysis; -using System.Globalization; -using System.Linq; -using System.Net.Http; -using System.Text.Json; -using Microsoft.AspNetCore.Components.WebAssembly.Services; -using Microsoft.DotNet.HotReload; -using Microsoft.JSInterop; - -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member - -namespace Microsoft.AspNetCore.Components.WebAssembly.HotReload; - -/// -/// Contains methods called by interop. Intended for framework use only, not supported for use in application -/// code. -/// -[EditorBrowsable(EditorBrowsableState.Never)] -[UnconditionalSuppressMessage( - "Trimming", - "IL2026:Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code", - Justification = "Hot Reload does not support trimming")] -public static partial class WebAssemblyHotReload -{ - /// - /// For framework use only. - /// - public readonly struct LogEntry - { - public string Message { get; init; } - public int Severity { get; init; } - } - - /// - /// For framework use only. - /// - internal sealed class Update - { - public int Id { get; set; } - public Delta[] Deltas { get; set; } = default!; - } - - /// - /// For framework use only. - /// - public readonly struct Delta - { - public string ModuleId { get; init; } - public byte[] MetadataDelta { get; init; } - public byte[] ILDelta { get; init; } - public byte[] PdbDelta { get; init; } - public int[] UpdatedTypes { get; init; } - } - - private static readonly AgentReporter s_reporter = new(); - private static readonly JsonSerializerOptions s_jsonSerializerOptions = new(JsonSerializerDefaults.Web); - - private static bool s_initialized; - private static HotReloadAgent? s_hotReloadAgent; - - internal static async Task InitializeAsync() - { - if (Environment.GetEnvironmentVariable("__ASPNETCORE_BROWSER_TOOLS") == "true" && - OperatingSystem.IsBrowser()) - { - s_initialized = true; - - var agent = new HotReloadAgent(); - - var existingAgent = Interlocked.CompareExchange(ref s_hotReloadAgent, agent, null); - if (existingAgent != null) - { - throw new InvalidOperationException("Hot Reload agent already initialized"); - } - - await ApplyPreviousDeltasAsync(agent); - } - } - - private static async ValueTask ApplyPreviousDeltasAsync(HotReloadAgent agent) - { - string errorMessage; - - using var client = new HttpClient() - { - BaseAddress = new Uri(WebAssemblyNavigationManager.Instance.BaseUri, UriKind.Absolute) - }; - - try - { - var response = await client.GetAsync("/_framework/blazor-hotreload"); - if (response.IsSuccessStatusCode) - { - var deltasJson = await response.Content.ReadAsStringAsync(); - var updates = deltasJson != "" ? JsonSerializer.Deserialize(deltasJson, s_jsonSerializerOptions) : null; - if (updates == null) - { - s_reporter.Report($"No previous updates to apply.", AgentMessageSeverity.Verbose); - return; - } - - var i = 1; - foreach (var update in updates) - { - s_reporter.Report($"Reapplying update {i}/{updates.Length}.", AgentMessageSeverity.Verbose); - - agent.ApplyDeltas( - update.Deltas.Select(d => new UpdateDelta(Guid.Parse(d.ModuleId, CultureInfo.InvariantCulture), d.MetadataDelta, d.ILDelta, d.PdbDelta, d.UpdatedTypes))); - - i++; - } - - return; - } - - errorMessage = $"HTTP GET '/_framework/blazor-hotreload' returned {response.StatusCode}"; - } - catch (Exception e) - { - errorMessage = e.ToString(); - } - - s_reporter.Report($"Failed to retrieve and apply previous deltas from the server: ${errorMessage}", AgentMessageSeverity.Error); - } - - private static HotReloadAgent? GetAgent() - => s_hotReloadAgent ?? (s_initialized ? throw new InvalidOperationException("Hot Reload agent not initialized") : null); - - /// - /// For framework use only. - /// - [Obsolete("Use ApplyHotReloadDeltas instead")] - [JSInvokable(nameof(ApplyHotReloadDelta))] - public static void ApplyHotReloadDelta(string moduleIdString, byte[] metadataDelta, byte[] ilDelta, byte[] pdbBytes, int[]? updatedTypes) - { - GetAgent()?.ApplyDeltas( - [new UpdateDelta(Guid.Parse(moduleIdString, CultureInfo.InvariantCulture), metadataDelta, ilDelta, pdbBytes, updatedTypes ?? [])]); - } - - /// - /// For framework use only. - /// - [JSInvokable(nameof(ApplyHotReloadDeltas))] - public static LogEntry[] ApplyHotReloadDeltas(Delta[] deltas, int loggingLevel) - { - var agent = GetAgent(); - - agent?.ApplyDeltas( - deltas.Select(d => new UpdateDelta(Guid.Parse(d.ModuleId, CultureInfo.InvariantCulture), d.MetadataDelta, d.ILDelta, d.PdbDelta, d.UpdatedTypes))); - - return s_reporter.GetAndClearLogEntries((ResponseLoggingLevel)loggingLevel) - .Select(log => new LogEntry() { Message = log.message, Severity = (int)log.severity }).ToArray(); - } - - /// - /// For framework use only. - /// - [JSInvokable(nameof(GetApplyUpdateCapabilities))] - public static string GetApplyUpdateCapabilities() - => GetAgent()?.Capabilities ?? ""; -} diff --git a/src/Components/WebAssembly/WebAssembly/src/PublicAPI.Unshipped.txt b/src/Components/WebAssembly/WebAssembly/src/PublicAPI.Unshipped.txt index fc7b59f8f640..7cfa4804d26b 100644 --- a/src/Components/WebAssembly/WebAssembly/src/PublicAPI.Unshipped.txt +++ b/src/Components/WebAssembly/WebAssembly/src/PublicAPI.Unshipped.txt @@ -1,24 +1,8 @@ #nullable enable Microsoft.AspNetCore.Components.WebAssembly.Hosting.WebAssemblyHostBuilder.UseServiceProviderOptions(Microsoft.Extensions.DependencyInjection.ServiceProviderOptions! options) -> Microsoft.AspNetCore.Components.WebAssembly.Hosting.WebAssemblyHostBuilder! Microsoft.AspNetCore.Components.WebAssembly.Hosting.WebAssemblyHostBuilderExtensions -Microsoft.AspNetCore.Components.WebAssembly.HotReload.WebAssemblyHotReload.Delta -Microsoft.AspNetCore.Components.WebAssembly.HotReload.WebAssemblyHotReload.Delta.Delta() -> void -Microsoft.AspNetCore.Components.WebAssembly.HotReload.WebAssemblyHotReload.Delta.ILDelta.get -> byte[]! -Microsoft.AspNetCore.Components.WebAssembly.HotReload.WebAssemblyHotReload.Delta.ILDelta.init -> void -Microsoft.AspNetCore.Components.WebAssembly.HotReload.WebAssemblyHotReload.Delta.MetadataDelta.get -> byte[]! -Microsoft.AspNetCore.Components.WebAssembly.HotReload.WebAssemblyHotReload.Delta.MetadataDelta.init -> void -Microsoft.AspNetCore.Components.WebAssembly.HotReload.WebAssemblyHotReload.Delta.ModuleId.get -> string! -Microsoft.AspNetCore.Components.WebAssembly.HotReload.WebAssemblyHotReload.Delta.ModuleId.init -> void -Microsoft.AspNetCore.Components.WebAssembly.HotReload.WebAssemblyHotReload.Delta.PdbDelta.get -> byte[]! -Microsoft.AspNetCore.Components.WebAssembly.HotReload.WebAssemblyHotReload.Delta.PdbDelta.init -> void -Microsoft.AspNetCore.Components.WebAssembly.HotReload.WebAssemblyHotReload.Delta.UpdatedTypes.get -> int[]! -Microsoft.AspNetCore.Components.WebAssembly.HotReload.WebAssemblyHotReload.Delta.UpdatedTypes.init -> void -Microsoft.AspNetCore.Components.WebAssembly.HotReload.WebAssemblyHotReload.LogEntry -Microsoft.AspNetCore.Components.WebAssembly.HotReload.WebAssemblyHotReload.LogEntry.LogEntry() -> void -Microsoft.AspNetCore.Components.WebAssembly.HotReload.WebAssemblyHotReload.LogEntry.Message.get -> string! -Microsoft.AspNetCore.Components.WebAssembly.HotReload.WebAssemblyHotReload.LogEntry.Message.init -> void -Microsoft.AspNetCore.Components.WebAssembly.HotReload.WebAssemblyHotReload.LogEntry.Severity.get -> int -Microsoft.AspNetCore.Components.WebAssembly.HotReload.WebAssemblyHotReload.LogEntry.Severity.init -> void static Microsoft.AspNetCore.Components.WebAssembly.Hosting.WebAssemblyHostBuilderExtensions.UseDefaultServiceProvider(this Microsoft.AspNetCore.Components.WebAssembly.Hosting.WebAssemblyHostBuilder! builder, System.Action! configure) -> Microsoft.AspNetCore.Components.WebAssembly.Hosting.WebAssemblyHostBuilder! static Microsoft.AspNetCore.Components.WebAssembly.Hosting.WebAssemblyHostBuilderExtensions.UseDefaultServiceProvider(this Microsoft.AspNetCore.Components.WebAssembly.Hosting.WebAssemblyHostBuilder! builder, System.Action! configure) -> Microsoft.AspNetCore.Components.WebAssembly.Hosting.WebAssemblyHostBuilder! -static Microsoft.AspNetCore.Components.WebAssembly.HotReload.WebAssemblyHotReload.ApplyHotReloadDeltas(Microsoft.AspNetCore.Components.WebAssembly.HotReload.WebAssemblyHotReload.Delta[]! deltas, int loggingLevel) -> Microsoft.AspNetCore.Components.WebAssembly.HotReload.WebAssemblyHotReload.LogEntry[]! +*REMOVED*Microsoft.AspNetCore.Components.WebAssembly.HotReload.WebAssemblyHotReload +*REMOVED*static Microsoft.AspNetCore.Components.WebAssembly.HotReload.WebAssemblyHotReload.ApplyHotReloadDelta(string! moduleIdString, byte[]! metadataDelta, byte[]! ilDelta, byte[]! pdbBytes, int[]? updatedTypes) -> void +*REMOVED*static Microsoft.AspNetCore.Components.WebAssembly.HotReload.WebAssemblyHotReload.GetApplyUpdateCapabilities() -> string! diff --git a/src/Components/WebAssembly/WebAssembly/src/targets/Microsoft.AspNetCore.Components.WebAssembly.props b/src/Components/WebAssembly/WebAssembly/src/targets/Microsoft.AspNetCore.Components.WebAssembly.props index 6eb5c1ba4feb..f8387e44dbdb 100644 --- a/src/Components/WebAssembly/WebAssembly/src/targets/Microsoft.AspNetCore.Components.WebAssembly.props +++ b/src/Components/WebAssembly/WebAssembly/src/targets/Microsoft.AspNetCore.Components.WebAssembly.props @@ -2,7 +2,6 @@ $(MSBuildThisFileDirectory)blazor.webassembly.js false - Baseline;AddMethodToExistingType;AddStaticFieldToExistingType;NewTypeDefinition;ChangeCustomAttributes;AddInstanceFieldToExistingType;GenericAddMethodToExistingType;GenericUpdateMethod;UpdateParameters;GenericAddFieldToExistingType