-
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
base: main
Are you sure you want to change the base?
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 an issue where Blazor 404 re-execution was not working properly when the Router component had an OnNavigateAsync
handler. The fix allows rendering to proceed during 404 re-execution scenarios while still preventing it during client-side navigation when lazy loading is in progress.
Key changes:
- Modified the Router component to differentiate between server-side rendering (SSR) scenarios and client-side navigation
- Updated the navigation blocking logic to check if route data is available from SSR before blocking rendering
- Added comprehensive test coverage for the 404 re-execution scenario with
OnNavigateAsync
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
File | Description |
---|---|
src/Components/Components/src/Routing/Router.cs | Updated navigation logic to allow rendering during SSR/re-execution while maintaining blocking for client navigation |
src/Components/test/testassets/Components.TestServer/RazorComponents/App.razor | Added test infrastructure with configurable OnNavigateAsync handler and query parameter support |
src/Components/test/E2ETest/ServerRenderingTests/NoInteractivityTest.cs | Added end-to-end test to verify 404 re-execution works with OnNavigateAsync |
src/Components/test/testassets/Components.TestServer/RazorComponents/App.razor
Outdated
Show resolved
Hide resolved
src/Components/test/E2ETest/ServerRenderingTests/NoInteractivityTest.cs
Outdated
Show resolved
Hide resolved
…onents/App.razor Co-authored-by: Copilot <[email protected]>
…tyTest.cs Co-authored-by: Copilot <[email protected]>
Failures of |
…NavigateAsync_ReExecutesTo404 test.
Do not prevent rendering for router that has
OnNavigateAsync
when navigation already started.In #24225 we blocked rendering for router that has
OnNavigateAsync
that is typically used for lazy loading actions. The reason was that rendering was throwing when triggered before with lazy loading finished: #24211.With rendering blocked, 404 re-execution mechanism is not able to render the contents of 404 page. We have to implement logic to inform Router that request re-execution happened and prevent rendering blocking in that case. To do it, we're embedding a flag in
RouteData
.Description
OnNavigateAsync
in progress ifRefresh
is triggered by re-execution.__BlazorAllowRenderDuringPendingNavigation
flag toRouteData
. In order to avoid regressing Lazy loading might encounter issues if host page rerenders during loading #24211, communication between endpoint renderer and router is necessary. Endpoint renderer has the information if request was re-executed. Router needs this information to decide if it's dealing with a Refresh that is supposed to wait forOnNavigateAsync
completion and block rendering until it's finished (to assure e.g. that assemblies that would be lazy loaded in thatOnNavigateAsync
are not missing during rendering). Or if it's dealing with Refresh after re-execution when we expect 404 page render and cannot block the rendering.OnNavigateAsync
task finishes. That test reflects the issue in more details than the one originally covering the fix and that does not fail when the regression really happens.Fixes #63933