Skip to content

Conversation

@javiercn
Copy link
Member

@javiercn javiercn commented Dec 10, 2025

[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 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

Customer Impact

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.

Regression?

  • Yes
  • 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.

Risk

  • High
  • Medium
  • 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.

Verification

  • Manual (required)
  • Automated

Packaging changes reviewed?

  • Yes
  • No
  • N/A

When servicing release/10.0

  • Make necessary changes in eng/PatchConfig.props

javiercn and others added 2 commits December 10, 2025 13:53
…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>
@javiercn javiercn requested a review from a team as a code owner December 10, 2025 13:12
Copilot AI review requested due to automatic review settings December 10, 2025 13:12
Copy link
Contributor

Copilot AI left a 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 isBlazorWeb flag to distinguish blazor.web.js from 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants