Skip to content

Commit 0ca7a9a

Browse files
committed
Use MetadataUpdater.IsSupported to determine if application supports hot reload
Fixes #33477
1 parent 23a699c commit 0ca7a9a

File tree

16 files changed

+29
-42
lines changed

16 files changed

+29
-42
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/Microsoft.AspNetCore.Components.csproj

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

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: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System;
55
using System.Diagnostics.CodeAnalysis;
6+
using System.Reflection.Metadata;
67
using Microsoft.AspNetCore.Components.HotReload;
78
using Microsoft.AspNetCore.Components.RenderTree;
89

@@ -45,9 +46,9 @@ public Dispatcher Dispatcher
4546
public bool IsInitialized => _renderer is not null;
4647

4748
/// <summary>
48-
/// Gets a value that determines if the <see cref="Renderer"/> is triggering a render in response to a hot-reload change.
49+
/// Gets a value that determines if the <see cref="Renderer"/> is triggering a render in response to a metadata update (hot-reload) change.
4950
/// </summary>
50-
public bool IsHotReloading => HotReloadFeature.IsSupported && (_renderer?.IsHotReloading ?? false);
51+
public bool IsMetadataUpdating => MetadataUpdater.IsSupported && (_renderer?.IsMetadataUpdating ?? false);
5152

5253
/// <summary>
5354
/// Notifies the renderer that the component should be rendered.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
using System;
77
using System.Collections.Generic;
8-
using Microsoft.AspNetCore.Components.HotReload;
8+
using System.Reflection.Metadata;
99
using Microsoft.AspNetCore.Components.Rendering;
1010

1111
namespace Microsoft.AspNetCore.Components.RenderTree
@@ -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) || (MetadataUpdater.IsSupported && diffContext.Renderer.IsMetadataUpdating))
546546
{
547547
componentState.SetDirectParameters(newParameters);
548548
}

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.Collections.Generic;
88
using System.Diagnostics;
99
using System.Diagnostics.CodeAnalysis;
10+
using System.Reflection.Metadata;
1011
using System.Threading;
1112
using System.Threading.Tasks;
1213
using Microsoft.AspNetCore.Components.HotReload;
@@ -97,7 +98,7 @@ public Renderer(IServiceProvider serviceProvider, ILoggerFactory loggerFactory,
9798
_logger = loggerFactory.CreateLogger<Renderer>();
9899
_componentFactory = new ComponentFactory(componentActivator);
99100

100-
if (HotReloadFeature.IsSupported)
101+
if (MetadataUpdater.IsSupported)
101102
{
102103
HotReloadManager.OnDeltaApplied += RenderRootComponentsOnHotReload;
103104
}
@@ -121,9 +122,9 @@ private static IComponentActivator GetComponentActivatorOrDefault(IServiceProvid
121122
protected internal ElementReferenceContext? ElementReferenceContext { get; protected set; }
122123

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

128129
private async void RenderRootComponentsOnHotReload()
129130
{
@@ -138,7 +139,7 @@ await Dispatcher.InvokeAsync(() =>
138139
return;
139140
}
140141

141-
IsHotReloading = true;
142+
IsMetadataUpdating = true;
142143
try
143144
{
144145
foreach (var (componentState, initialParameters) in _rootComponents)
@@ -148,7 +149,7 @@ await Dispatcher.InvokeAsync(() =>
148149
}
149150
finally
150151
{
151-
IsHotReloading = false;
152+
IsMetadataUpdating = false;
152153
}
153154
});
154155
}
@@ -226,7 +227,7 @@ protected async Task RenderRootComponentAsync(int componentId, ParameterView ini
226227
// During the asynchronous rendering process we want to wait up until all components have
227228
// finished rendering so that we can produce the complete output.
228229
var componentState = GetRequiredComponentState(componentId);
229-
if (HotReloadFeature.IsSupported)
230+
if (MetadataUpdater.IsSupported)
230231
{
231232
// when we're doing hot-reload, stash away the parameters used while rendering root components.
232233
// We'll use this to trigger re-renders on hot reload updates.
@@ -997,7 +998,7 @@ public void Dispose()
997998
/// <inheritdoc />
998999
public async ValueTask DisposeAsync()
9991000
{
1000-
if (HotReloadFeature.IsSupported)
1001+
if (MetadataUpdater.IsSupported)
10011002
{
10021003
HotReloadManager.OnDeltaApplied -= RenderRootComponentsOnHotReload;
10031004
}

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
}

src/Components/Forms/src/EditContextDataAnnotationsExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public DataAnnotationsEventSubscriptions(EditContext editContext)
6363
_editContext.OnFieldChanged += OnFieldChanged;
6464
_editContext.OnValidationRequested += OnValidationRequested;
6565

66-
if (HotReloadFeature.IsSupported)
66+
if (MetadataUpdater.IsSupported)
6767
{
6868
OnClearCache += ClearCache;
6969
}
@@ -132,7 +132,7 @@ public void Dispose()
132132
_editContext.OnValidationRequested -= OnValidationRequested;
133133
_editContext.NotifyValidationStateChanged();
134134

135-
if (HotReloadFeature.IsSupported)
135+
if (MetadataUpdater.IsSupported)
136136
{
137137
OnClearCache -= ClearCache;
138138
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
<ItemGroup>
1717
<Reference Include="Microsoft.AspNetCore.Components" />
18-
<Compile Include="$(ComponentsSharedSourceRoot)src\HotReloadFeature.cs" LinkBase="HotReload" />
1918
</ItemGroup>
2019

2120
<ItemGroup>

src/Components/Shared/src/HotReloadFeature.cs

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)