Draft
Conversation
Copilot created this pull request from a session on behalf of
pavelsavara
March 23, 2026 00:13
View session
afe574f to
e83a0f7
Compare
This was referenced Mar 26, 2026
Open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix hot reload IL trimming
Summary
This PR improves IL trimming effectiveness for Blazor WebAssembly apps by making the hot reload feature switch properly recognized by the IL trimmer. Previously, hot reload–related code (caches, event subscriptions, metadata update handlers) was not trimmed away in published WASM apps because the trimmer could not statically determine that
MetadataUpdater.IsSupportedwasfalse.Problem
HotReloadManager.MetadataUpdateSupportedwas backed byMetadataUpdater.IsSupported, which returnsfalseat runtime in trimmed/published WASM builds. However, the IL trimmer could not prove this statically. As a result:HotReloadManagertype itself and its dependency graph survived trimming.Solution
Introduced
HotReloadManager.IsSupported— astatic boolproperty annotated with[FeatureSwitchDefinition("System.Reflection.Metadata.MetadataUpdater.IsSupported")]. This tells the IL trimmer to substitute this property withfalsewhen the feature switch is disabled, enabling it to eliminate dead code behind the guard.Split the check into two levels:
HotReloadManager.IsSupported(static, trimmer-visible) — controls whether any hot reload infrastructure is linked.HotReloadManager.IsEnabled(instance, runtime-mutable) — replaces the oldMetadataUpdateSupportedproperty, used for testing scenarios where hot reload behavior needs to be toggled at runtime.Updated all ~20 call sites from:
to:
The static
IsSupportedcheck comes first so the trimmer can eliminate the entireifblock (including theIsEnabledaccess and the callback registration) when the feature is disabled.Updated
Rendererto use the same two-level guard pattern, replacing direct references to the old staticHotReloadManager.MetadataUpdateSupported.Updated ILLink substitutions in
ILLink.Substitutions.xmlto target the newget_IsSupportedmethod.Testing
RendererTest.cs): Updated to use the newIsEnabledproperty for controlling hot reload behavior in tests.WebAssemblyTrimmingTest.cs): Added a new test that verifiesHotReloadManagertype is trimmed away in published WASM builds. Uses reflection (Type.GetType) to confirm the type is absent in trimmed output.HotReloadTrimmingCheck.razor): A Blazor component that checks at runtime whetherHotReloadManageris present via reflection, reportingtrue/false.Files changed
Core change
HotReloadManager.cs— Added[FeatureSwitchDefinition]-annotatedIsSupportedproperty; renamedMetadataUpdateSupportedtoIsEnabled.Updated call sites (mechanical)
All files below changed from
HotReloadManager.Default.MetadataUpdateSupportedtoHotReloadManager.IsSupported && HotReloadManager.Default.IsEnabled:AttributeAuthorizeDataCache.csBindConverter.csChangeDetection.csComponentFactory.csDefaultComponentActivator.csDefaultComponentPropertyActivator.csPersistentServicesRegistry.csPersistentStateValueProviderKeyResolver.csPersistentValueProviderComponentSubscription.csComponentProperties.csRenderHandle.csEventArgsTypeCache.csRenderTreeDiffBuilder.csRenderer.csRouteView.csRouteTable.csRouter.csEndpointComponentState.csFieldIdentifier.csExpressionFormatter.csRootTypeCache.csExpressionMemberAccessor.csJSComponentInterop.csTrimmer configuration
ILLink.Substitutions.xml— Updated method signature fromget_MetadataUpdateSupportedtoget_IsSupported.Tests
RendererTest.cs— Updated to useIsEnabledinstead ofMetadataUpdateSupported.WebAssemblyTrimmingTest.cs— New E2E test verifyingHotReloadManageris trimmed in WASM publish.HotReloadTrimmingCheck.razor— New test component for runtime type presence check.Index.razor— Registered the new test component.Components.TestServer.csproj— SetMetadataUpdaterSupport=truefor trimmed test builds.HotReloadStartup.cs— Updated to useIsEnabled.