Skip to content

Commit 5073e12

Browse files
committed
Use MetadataUpdater.IsSupported to determine if application supports hot reload
Fixes #33477
1 parent 51dfc46 commit 5073e12

23 files changed

+45
-71
lines changed

src/Components/Components/src/ComponentBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ protected void StateHasChanged()
102102
return;
103103
}
104104

105-
if (_hasNeverRendered || ShouldRender() || _renderHandle.IsHotReloading)
105+
if (_hasNeverRendered || ShouldRender() || _renderHandle.IsMetadataUpdating)
106106
{
107107
_hasPendingQueuedRender = true;
108108

src/Components/Components/src/HotReload/HotReloadManager.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ namespace Microsoft.AspNetCore.Components.HotReload
1111
{
1212
internal static class HotReloadManager
1313
{
14-
internal static event Action? OnDeltaApplied;
14+
public static bool TestIsHotReloadSupported { get; set; }
15+
16+
public static bool IsHotReloadSupported => MetadataUpdater.IsSupported || TestIsHotReloadSupported;
17+
18+
internal static event Action? OnDeltaApplied;
1519

1620
public static void DeltaApplied()
1721
{

src/Components/Components/src/Microsoft.AspNetCore.Components.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
<ItemGroup>
1414
<Compile Include="$(ComponentsSharedSourceRoot)src\ArrayBuilder.cs" LinkBase="RenderTree" />
1515
<Compile Include="$(ComponentsSharedSourceRoot)src\JsonSerializerOptionsProvider.cs" />
16-
<Compile Include="$(ComponentsSharedSourceRoot)src\HotReloadFeature.cs" LinkBase="HotReload" />
1716
<Compile Include="$(SharedSourceRoot)LinkerFlags.cs" LinkBase="Shared" />
1817
<Compile Include="$(SharedSourceRoot)QueryStringEnumerable.cs" LinkBase="Shared" />
1918
</ItemGroup>

src/Components/Components/src/Properties/AssemblyInfo.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
14
using System.Runtime.CompilerServices;
25

36
[assembly: InternalsVisibleTo("Microsoft.AspNetCore.Blazor.Build.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")]
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<linker>
22
<assembly fullname="Microsoft.AspNetCore.Components">
3-
<type fullname="Microsoft.AspNetCore.Components.HotReload.HotReloadFeature" feature="System.Diagnostics.Debugger.IsSupported" featurevalue="false">
4-
<method signature="System.Boolean get_IsSupported()" body="stub" value="false" />
3+
<type fullname="Microsoft.AspNetCore.Components.HotReload.HotReloadManager" feature="System.Reflection.Metadata.MetadataUpdater.IsSupported" featurevalue="false">
4+
<method signature="System.Boolean get_IsHotReloadSupported()" body="stub" value="false" />
55
</type>
66
</assembly>
77
</linker>

src/Components/Components/src/PublicAPI.Unshipped.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Microsoft.AspNetCore.Components.NavigationOptions.ForceLoad.init -> void
4040
Microsoft.AspNetCore.Components.NavigationOptions.NavigationOptions() -> void
4141
Microsoft.AspNetCore.Components.NavigationOptions.ReplaceHistoryEntry.get -> bool
4242
Microsoft.AspNetCore.Components.NavigationOptions.ReplaceHistoryEntry.init -> void
43-
Microsoft.AspNetCore.Components.RenderHandle.IsHotReloading.get -> bool
43+
Microsoft.AspNetCore.Components.RenderHandle.IsMetadataUpdating.get -> bool
4444
Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder.Dispose() -> void
4545
Microsoft.AspNetCore.Components.Routing.Router.PreferExactMatches.get -> bool
4646
Microsoft.AspNetCore.Components.Routing.Router.PreferExactMatches.set -> void

src/Components/Components/src/RenderHandle.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public Dispatcher Dispatcher
4747
/// <summary>
4848
/// Gets a value that determines if the <see cref="Renderer"/> is triggering a render in response to a hot-reload change.
4949
/// </summary>
50-
public bool IsHotReloading => HotReloadFeature.IsSupported && (_renderer?.IsHotReloading ?? false);
50+
public bool IsMetadataUpdating => HotReloadManager.IsHotReloadSupported && (_renderer?.IsMetadataUpdating ?? false);
5151

5252
/// <summary>
5353
/// Notifies the renderer that the component should be rendered.

src/Components/Components/src/RenderTree/RenderTreeDiffBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ private static void UpdateRetainedChildComponent(
542542
var oldParameters = new ParameterView(ParameterViewLifetime.Unbound, oldTree, oldComponentIndex);
543543
var newParametersLifetime = new ParameterViewLifetime(diffContext.BatchBuilder);
544544
var newParameters = new ParameterView(newParametersLifetime, newTree, newComponentIndex);
545-
if (!newParameters.DefinitelyEquals(oldParameters) || (HotReloadFeature.IsSupported && diffContext.Renderer.IsHotReloading))
545+
if (!newParameters.DefinitelyEquals(oldParameters) || (HotReloadManager.IsHotReloadSupported && diffContext.Renderer.IsMetadataUpdating))
546546
{
547547
componentState.SetDirectParameters(newParameters);
548548
}

src/Components/Components/src/RenderTree/Renderer.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public Renderer(IServiceProvider serviceProvider, ILoggerFactory loggerFactory,
9797
_logger = loggerFactory.CreateLogger<Renderer>();
9898
_componentFactory = new ComponentFactory(componentActivator);
9999

100-
if (HotReloadFeature.IsSupported)
100+
if (HotReloadManager.IsHotReloadSupported)
101101
{
102102
HotReloadManager.OnDeltaApplied += RenderRootComponentsOnHotReload;
103103
}
@@ -121,9 +121,9 @@ private static IComponentActivator GetComponentActivatorOrDefault(IServiceProvid
121121
protected internal ElementReferenceContext? ElementReferenceContext { get; protected set; }
122122

123123
/// <summary>
124-
/// Gets a value that determines if the <see cref="Renderer"/> is triggering a render in response to a hot-reload change.
124+
/// Gets a value that determines if the <see cref="Renderer"/> is triggering a render in response to a (metadata update) hot-reload change.
125125
/// </summary>
126-
internal bool IsHotReloading { get; private set; }
126+
internal bool IsMetadataUpdating { get; private set; }
127127

128128
private async void RenderRootComponentsOnHotReload()
129129
{
@@ -139,7 +139,7 @@ await Dispatcher.InvokeAsync(() =>
139139
return;
140140
}
141141

142-
IsHotReloading = true;
142+
IsMetadataUpdating = true;
143143
try
144144
{
145145
foreach (var (componentState, initialParameters) in _rootComponents)
@@ -149,7 +149,7 @@ await Dispatcher.InvokeAsync(() =>
149149
}
150150
finally
151151
{
152-
IsHotReloading = false;
152+
IsMetadataUpdating = false;
153153
}
154154
});
155155
}
@@ -227,7 +227,7 @@ protected async Task RenderRootComponentAsync(int componentId, ParameterView ini
227227
// During the asynchronous rendering process we want to wait up until all components have
228228
// finished rendering so that we can produce the complete output.
229229
var componentState = GetRequiredComponentState(componentId);
230-
if (HotReloadFeature.IsSupported)
230+
if (HotReloadManager.IsHotReloadSupported)
231231
{
232232
// when we're doing hot-reload, stash away the parameters used while rendering root components.
233233
// We'll use this to trigger re-renders on hot reload updates.
@@ -998,7 +998,7 @@ public void Dispose()
998998
/// <inheritdoc />
999999
public async ValueTask DisposeAsync()
10001000
{
1001-
if (HotReloadFeature.IsSupported)
1001+
if (HotReloadManager.IsHotReloadSupported)
10021002
{
10031003
HotReloadManager.OnDeltaApplied -= RenderRootComponentsOnHotReload;
10041004
}

src/Components/Components/src/Routing/Router.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System;
77
using System.Collections.Generic;
88
using System.Reflection;
9+
using System.Reflection.Metadata;
910
using System.Runtime.ExceptionServices;
1011
using System.Threading;
1112
using System.Threading.Tasks;
@@ -99,7 +100,7 @@ public void Attach(RenderHandle renderHandle)
99100
_locationAbsolute = NavigationManager.Uri;
100101
NavigationManager.LocationChanged += OnLocationChanged;
101102

102-
if (HotReloadFeature.IsSupported)
103+
if (MetadataUpdater.IsSupported)
103104
{
104105
HotReloadManager.OnDeltaApplied += ClearRouteCaches;
105106
}
@@ -143,7 +144,7 @@ public async Task SetParametersAsync(ParameterView parameters)
143144
public void Dispose()
144145
{
145146
NavigationManager.LocationChanged -= OnLocationChanged;
146-
if (HotReloadFeature.IsSupported)
147+
if (MetadataUpdater.IsSupported)
147148
{
148149
HotReloadManager.OnDeltaApplied -= ClearRouteCaches;
149150
}

0 commit comments

Comments
 (0)