-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Fix hot reload routing issue by validating route templates in EndpointHtmlRenderer #63737
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
Draft
Copilot
wants to merge
6
commits into
main
Choose a base branch
from
copilot/fix-5f15cc26-6f24-4f37-af4a-6f7db94b69da
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1586c87
Initial plan
Copilot 8271b88
Fix hot reload routing issue with stale template handling
Copilot bb16b3b
Add comprehensive tests for hot reload routing fix
Copilot cdce445
Fix hot reload routing by invalidating cached route data
Copilot caad798
Clean up test file and finalize hot reload routing fix
Copilot a4d6cf9
Rework hot reload fix - validate route template against component att…
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
25 changes: 24 additions & 1 deletion
25
src/Components/Endpoints/src/DependencyInjection/EndpointRoutingStateProvider.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,34 @@ | ||
// 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 Microsoft.AspNetCore.Components.Routing; | ||
|
||
namespace Microsoft.AspNetCore.Components.Endpoints.DependencyInjection; | ||
|
||
internal sealed class EndpointRoutingStateProvider : IRoutingStateProvider | ||
{ | ||
public RouteData? RouteData { get; internal set; } | ||
private static volatile bool _cacheInvalidated; | ||
private RouteData? _routeData; | ||
|
||
static EndpointRoutingStateProvider() | ||
{ | ||
if (HotReloadManager.Default.MetadataUpdateSupported) | ||
{ | ||
HotReloadManager.Default.OnDeltaApplied += InvalidateCache; | ||
} | ||
} | ||
|
||
public RouteData? RouteData | ||
{ | ||
get => _cacheInvalidated ? null : _routeData; | ||
internal set => _routeData = value; | ||
} | ||
|
||
private static void InvalidateCache() | ||
{ | ||
// Invalidate cached route data during hot reload to prevent stale route data | ||
// from being used when component route templates change | ||
_cacheInvalidated = true; | ||
} | ||
} |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
@copilot
_routeData
is a non-static field yet you treat it as a static cache. This does not seem correct.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.
@copilot Rework the solution. Investigate how the
EndpointRoutingStateProvider
is used.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.
You're absolutely right about the flawed design. I've reworked the solution to fix the root cause in
EndpointHtmlRenderer
instead of using a broken static flag approach.The new solution validates that the endpoint's route template matches the component's current route attributes before setting the template. When they don't match (hot reload scenario), the template stays
null
, forcing the router to use normal routing with updated metadata. Commit: caad798