-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[10.0] [Blazor] Support NavigateTo when enhanced nav is disabled (#52267) #64724
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: release/10.0
Are you sure you want to change the base?
Conversation
…64542) * Support NavigateTo when enhanced nav is disabled (#52267) Makes the NavigateTo API work even if enhanced nav is disabled via config. By default, Blazor apps have either enhanced nav or an interactive router . In these default cases, the `NavigateTo` API works correctly. However there's also an obscure way to disable both of these via config. It's niche, but it's supported, so the rest of the system should work with that. Unfortunately `NavigateTo` assumes that either enhanced nav or an interactive router will be enabled and doesn't account for the case when neither is. Fixes #51636 Without this fix, anyone who uses the `ssr: { disableDomPreservation: true }` config option will be unable to use the `NavigateTo` API, as it will do nothing. This behavior isn't desirable. - [ ] Yes - [x] No No because existing code can't use `ssr: { disableDomPreservation: true }` as the option didn't exist prior to .NET 8. Someone else might argue that it's a regression in the sense that, if you're migrating existing code to use newer .NET 8 patterns (and are using `disableDomPreservation` for some reason, even though you wouldn't normally), your existing uses of `NavigateTo` could stop working. That's not how we normally define "regression" but I'm trying to give the fullest explanation. - [ ] High - [ ] Medium - [x] Low The fix explicitly retains the old code path if you're coming from .NET 7 or earlier (i.e., if you are using `blazor.webassembly/server/webview.js`. The fixed code path is only applied in `blazor.web.js`, so it should not affect existing apps that are simply moving to the `net8.0` TFM without other code changes. - [x] Manual (required) - [x] Automated - [ ] Yes - [ ] No - [x] N/A * Remove redundant IsElementStale method and use WebDriverExtensions.IsStale (#64549) * Initial plan * Remove redundant IsElementStale method and use WebDriverExtensions.IsStale Co-authored-by: javiercn <6995051+javiercn@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: javiercn <6995051+javiercn@users.noreply.github.com> * Remove IsElementStale method and use existing WebDriverExtensions.IsStale (#64550) * Initial plan * Remove IsElementStale and use WebDriverExtensions.IsStale Co-authored-by: ilonatommy <32700855+ilonatommy@users.noreply.github.com> * Remove unused private IsElementStale method from EnhancedNavigationTest.cs Co-authored-by: ilonatommy <32700855+ilonatommy@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: ilonatommy <32700855+ilonatommy@users.noreply.github.com> --------- Co-authored-by: Steve Sanderson <SteveSandersonMS@users.noreply.github.com> Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com> Co-authored-by: ilonatommy <32700855+ilonatommy@users.noreply.github.com>
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 a bug where the NavigateTo API fails to work when enhanced navigation is disabled via the ssr: { disableDomPreservation: true } configuration option. The fix introduces a new isBlazorWeb flag to differentiate between blazor.web.js and the older blazor.server.js/blazor.webassembly.js hosting models, allowing blazor.web.js to perform a full page load in scenarios where neither enhanced navigation nor an interactive router is available.
Key Changes:
- Refactored navigation logic to explicitly handle three page load mechanisms: client-side router, server-side enhanced navigation, and server-side full page load
- Added
isBlazorWebflag to distinguishblazor.web.jsfrom legacy hosting models for backward compatibility - Added comprehensive E2E tests covering all combinations of enhanced navigation and force load scenarios
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 |
|---|---|
| src/Components/Web.JS/src/Services/NavigationManager.ts | Refactored navigateToCore to explicitly handle three page load mechanisms; added currentPageLoadMechanism function to determine navigation strategy based on router availability and hosting model |
| src/Components/Web.JS/src/GlobalExports.ts | Added optional isBlazorWeb property to the IBlazor._internal interface to identify blazor.web.js hosting model |
| src/Components/Web.JS/src/Boot.Web.ts | Set Blazor._internal.isBlazorWeb = true during boot to identify blazor.web.js context |
| src/Components/test/E2ETest/Infrastructure/WebDriverExtensions/WebDriverExtensions.cs | Added IsStale extension method to check if WebElement references are stale after navigation |
| src/Components/test/testassets/Components.TestServer/RazorComponents/Pages/Interactivity/InteractiveNavigateTo.razor | New test component to verify NavigateTo functionality with buttons for normal and force-load navigation |
| src/Components/test/E2ETest/ServerRenderingTests/InteractivityTest.cs | Added parameterized test covering 4 scenarios for NavigateTo with/without enhanced navigation and force load |
| src/Components/test/testassets/Components.TestServer/RazorComponents/Shared/EnhancedNavLayout.razor | Wrapped @Body in semantic <main> element for improved HTML structure in test layout |
[10.0] [Blazor] Support NavigateTo when enhanced nav is disabled (#52267)
Makes the NavigateTo API work even if enhanced nav is disabled via config.
Description
By default, Blazor apps have either enhanced nav or an interactive router. In these default cases, the
NavigateToAPI works correctly.However there's also an obscure way to disable both of these via config. It's niche, but it's supported, so the rest of the system should work with that. Unfortunately
NavigateToassumes that either enhanced nav or an interactive router will be enabled and doesn't account for the case when neither is.Fixes #51636
Customer Impact
Without this fix, anyone who uses the
ssr: { disableDomPreservation: true }config option will be unable to use theNavigateToAPI, as it will do nothing. This behavior isn't desirable.Regression?
No because existing code can't use
ssr: { disableDomPreservation: true }as the option didn't exist prior to .NET 8.Someone else might argue that it's a regression in the sense that, if you're migrating existing code to use newer .NET 8 patterns (and are using
disableDomPreservationfor some reason, even though you wouldn't normally), your existing uses ofNavigateTocould stop working. That's not how we normally define "regression" but I'm trying to give the fullest explanation.Risk
The fix explicitly retains the old code path if you're coming from .NET 7 or earlier (i.e., if you are using
blazor.webassembly/server/webview.js. The fixed code path is only applied inblazor.web.js, so it should not affect existing apps that are simply moving to thenet8.0TFM without other code changes.Verification
Packaging changes reviewed?
When servicing release/10.0