-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Blazor 404 code re-execution is compatible with OnNavigateAsync
#64034
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
Open
ilonatommy
wants to merge
13
commits into
dotnet:main
Choose a base branch
from
ilonatommy:fix-63933
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.
+187
−10
Open
Changes from 11 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
0317ecf
Fix
ilonatommy d662028
Merge branch 'main' into fix-63933
ilonatommy c90449b
Update src/Components/test/testassets/Components.TestServer/RazorComp…
ilonatommy 64df78f
Update src/Components/test/E2ETest/ServerRenderingTests/NoInteractivi…
ilonatommy 5ed75df
Cleanup.
ilonatommy b8856ad
More cleanup.
ilonatommy d444c4a
Merge branch 'main' into fix-63933
ilonatommy 5f632fe
Prevent duplicate force-load navigations to keep the history intact.
ilonatommy 0f0cf6a
Add a better test for https://github.com/dotnet/aspnetcore/pull/24225…
ilonatommy f2fb811
Revert Router changes + fix BrowserNavigationToNotExistingPath_WithOn…
ilonatommy 496d430
Allow Router to bypass OnNavigateAsync guard during 404 re-execution.
ilonatommy e97518a
Move contants to shared file.
ilonatommy dd17b60
Remove useless directives.
ilonatommy 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
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
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
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
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
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
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
65 changes: 65 additions & 0 deletions
65
...ents/test/testassets/Components.TestServer/RazorComponents/NavigationCompletionTracker.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 |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System; | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
|
|
||
| namespace Components.TestServer.RazorComponents; | ||
|
|
||
| internal static class NavigationCompletionTracker | ||
| { | ||
| internal const string GuardSwitchName = "Components.TestServer.RazorComponents.UseNavigationCompletionGuard"; | ||
|
|
||
| private const string TrackedPathSuffix = "with-lazy-assembly"; | ||
| private static int _isNavigationTracked; | ||
| private static int _isNavigationCompleted; | ||
|
|
||
| public static bool TryGetGuardTask(string? path, out Task guardTask) | ||
| { | ||
| if (!IsGuardEnabledForPath(path)) | ||
| { | ||
| guardTask = Task.CompletedTask; | ||
| return false; | ||
| } | ||
|
|
||
| guardTask = TrackNavigationAsync(); | ||
| return true; | ||
| } | ||
|
|
||
| public static void AssertNavigationCompleted() | ||
| { | ||
| if (Volatile.Read(ref _isNavigationTracked) == 1 && Volatile.Read(ref _isNavigationCompleted) == 0) | ||
| { | ||
| throw new InvalidOperationException("Navigation finished before OnNavigateAsync work completed."); | ||
| } | ||
|
|
||
| Volatile.Write(ref _isNavigationTracked, 0); | ||
| } | ||
|
|
||
| private static bool IsGuardEnabledForPath(string? path) | ||
| { | ||
| if (!AppContext.TryGetSwitch(GuardSwitchName, out var isEnabled) || !isEnabled) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| return path is not null && path.EndsWith(TrackedPathSuffix, StringComparison.OrdinalIgnoreCase); | ||
| } | ||
|
|
||
| private static async Task TrackNavigationAsync() | ||
| { | ||
| Volatile.Write(ref _isNavigationTracked, 1); | ||
| Volatile.Write(ref _isNavigationCompleted, 0); | ||
|
|
||
| try | ||
| { | ||
| await Task.Yield(); | ||
| await Task.Delay(TimeSpan.FromMilliseconds(50)).ConfigureAwait(false); | ||
| } | ||
| finally | ||
| { | ||
| Volatile.Write(ref _isNavigationCompleted, 1); | ||
| } | ||
| } | ||
| } |
12 changes: 12 additions & 0 deletions
12
...est/testassets/Components.TestServer/RazorComponents/Pages/Routing/WithLazyAssembly.razor
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 |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| @page "/routing/with-lazy-assembly" | ||
| @using Components.TestServer.RazorComponents; | ||
|
|
||
| <h1 id="lazy-route-status">Lazy route rendered</h1> | ||
|
|
||
| @code | ||
| { | ||
| protected override void OnInitialized() | ||
| { | ||
| NavigationCompletionTracker.AssertNavigationCompleted(); | ||
| } | ||
| } |
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.