Fix hot reload for Blazor route changes#63972
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR fixes two critical bugs in Blazor hot reload functionality for route changes: premature change token disposal and stale route data caching.
- Moves change token disposal to prevent premature disposal before callbacks are invoked
- Replaces pre-built
ComponentApplicationBuilderinstances with configuration actions that are replayed on each update - Updates test code to work with the new action-based configuration approach
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| RazorComponentEndpointDataSource.cs | Core fix: replaces cached builder with action replay pattern and moves token disposal timing |
| RazorComponentsEndpointConventionBuilder.cs | Updates to store and expose configuration actions instead of direct builder reference |
| RazorComponentEndpointDataSourceFactory.cs | Changes to use action-based configuration for assembly registration |
| RazorComponentsEndpointConventionBuilderExtensions.cs | Updates assembly addition to use new action pattern |
| RazorComponentEndpointDataSourceTest.cs | Test updates to work with new action-based configuration |
| HotReloadServiceTests.cs | Comprehensive test refactoring to use new pattern and verify token disposal behavior |
| RazorComponentsEndpointConventionBuilderExtensionsTest.cs | Minor test update for new action pattern |
Co-authored-by: Copilot <[email protected]>
Member
|
/backport to release/10.0 |
Contributor
|
Started backporting to release/10.0: https://github.com/dotnet/aspnetcore/actions/runs/18383238424 |
11 tasks
javiercn
approved these changes
Oct 9, 2025
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.
Fixes two bugs that prevented hot reload from applying changes in Blazor routes.
Premature change token disposal
A bug introduced in #53750 caused the change token used by
RazorComponentEndpointDataSourceto be disposed before the callback registered on the token is invoked. This means thatUpdateEndpointsis not being called at all during hot reload.This PR does not remove the token disposal so that the memory leak is not re-introduced. Instead, the PR moves the disposal of the current token to
UpdateEndpointsitself. This is valid because the role of the change token is precisely to trigger the update and the token is replaced at the end ofUpdateEndpointswith a new one (as before).Stale route data
The first bug was previously hiding a further problem in how we cache route data used by the main ASP.NET Core routing. This data was computed once during application start up and then reused in every
UpdateEndpointsinvocation. This means that we did not re-scan the assemblies for added, modified, or removed routes.The PR changes the implementation of
RazorComponentEndpointDataSourceand related types so that we do not store a pre-built instance ofComponentApplicationBuilder. Instead we store a list of configuration actions that were invoked for the currentRazorComponentEndpointDataSource. When the route data needs to be updated, these actions are replayed on a newComponentApplicationBuilderinstance, thus ensuring an up-to-date state. Note that this follows the same pattern as we already use for endpoint conventions.Result
After the change, hot reload works as expected in the following scenarios:
Hot reload still does not work when deleting a page with route.
Fixes #52582