diff --git a/src/Components/Server/src/Microsoft.AspNetCore.Components.Server.csproj b/src/Components/Server/src/Microsoft.AspNetCore.Components.Server.csproj index a26f7d17f2d1..216f05e54134 100644 --- a/src/Components/Server/src/Microsoft.AspNetCore.Components.Server.csproj +++ b/src/Components/Server/src/Microsoft.AspNetCore.Components.Server.csproj @@ -39,6 +39,7 @@ + diff --git a/src/Components/Shared/src/RootTypeCache.cs b/src/Components/Shared/src/RootTypeCache.cs index 9c41b8cd1533..016ab5acd814 100644 --- a/src/Components/Shared/src/RootTypeCache.cs +++ b/src/Components/Shared/src/RootTypeCache.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using Microsoft.AspNetCore.Components.HotReload; using System.Collections.Concurrent; using System.Diagnostics.CodeAnalysis; using System.Reflection; @@ -12,10 +13,28 @@ namespace Microsoft.AspNetCore.Components; #endif // A cache for root component types -internal sealed class RootTypeCache +internal sealed class RootTypeCache : IDisposable { private readonly ConcurrentDictionary _typeToKeyLookUp = new(); + public RootTypeCache() + { + if (HotReloadManager.Default.MetadataUpdateSupported) + { + HotReloadManager.Default.OnDeltaApplied += ClearCache; + } + } + + internal void ClearCache() => _typeToKeyLookUp.Clear(); + + public void Dispose() + { + if (HotReloadManager.Default.MetadataUpdateSupported) + { + HotReloadManager.Default.OnDeltaApplied -= ClearCache; + } + } + public Type? GetRootType(string assembly, string type) { var key = new Key(assembly, type); diff --git a/src/Components/WebAssembly/WebAssembly/src/Microsoft.AspNetCore.Components.WebAssembly.csproj b/src/Components/WebAssembly/WebAssembly/src/Microsoft.AspNetCore.Components.WebAssembly.csproj index f0418fd10354..ba479f5352f7 100644 --- a/src/Components/WebAssembly/WebAssembly/src/Microsoft.AspNetCore.Components.WebAssembly.csproj +++ b/src/Components/WebAssembly/WebAssembly/src/Microsoft.AspNetCore.Components.WebAssembly.csproj @@ -24,6 +24,7 @@ +