-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Fix hot reload for Blazor route changes #63972
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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]>
|
/backport to release/10.0 |
|
Started backporting to release/10.0: https://github.com/dotnet/aspnetcore/actions/runs/18383238424 |
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