Skip to content

[release/10.0] [Blazor] Fix metadata comments incorrectly being processed as logical elements#64530

Merged
lewing merged 1 commit intorelease/10.0from
backport/pr-64529-to-release/10.0
Mar 3, 2026
Merged

[release/10.0] [Blazor] Fix metadata comments incorrectly being processed as logical elements#64530
lewing merged 1 commit intorelease/10.0from
backport/pr-64529-to-release/10.0

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

@github-actions github-actions bot commented Nov 25, 2025

Backport of #64529 to release/10.0

/cc @javiercn

Fix Blazor navigation error caused by metadata comments in logical tree

Prevent metadata comments from becoming logical elements during rendering

Description

This PR fixes a bug where Blazor metadata comments (such as WebAssembly options, component state, and initializers) were being converted into logical elements during the initial render. When these comments were later removed from the DOM during component discovery, they remained in the logical tree as orphaned references, causing insertBefore errors during subsequent navigation between different render modes.

The fix modifies toLogicalElement() in LogicalElements.ts to skip metadata comments before they enter the logical tree, using a new isMetadataComment() helper function in ComponentDescriptorDiscovery.ts that identifies all Blazor metadata comment types.

Fixes #64522, #64472

Customer Impact

Users experience JavaScript errors and navigation failures when navigating between pages with different render modes (InteractiveServer, InteractiveWebAssembly, or InteractiveAuto) in Blazor Web Apps. The error manifests as:

  • Uncaught TypeError: Cannot read properties of null (reading 'insertBefore')
  • Failed page transitions requiring full browser refresh
  • Broken user experience in production applications

This particularly affects applications using:

  • PageTitle components with different render modes
  • Navigation between InteractiveWebAssembly and InteractiveServer pages
  • Any scenario mixing render modes in a Blazor United application

Regression?

  • Yes
  • No

This is a regression introduced in .NET 10.0 when the WebAssembly options discovery mechanism was added. The <!--Blazor-WebAssembly:{...}--> comment is new to v10.0 and was not present in v9.0. The toLogicalElement() function was indiscriminately converting all nodes including these new metadata comments into logical elements, which caused the orphaning issue when the comments were removed from the DOM.

Risk

  • High
  • Medium
  • Low

Justification:

  • The fix is surgical and only affects the initial logical tree construction
  • It prevents a specific category of nodes (metadata comments) from entering the logical tree
  • Metadata comments were never intended to be logical elements - they are consumed during discovery
  • The fix aligns behavior with design intent: these comments are transient markers, not components
  • Extensively validated with two independent reproduction cases from separate bug reports
  • No changes to core rendering logic, only to node filtering during tree construction
  • The isMetadataComment() function uses explicit prefix matching with well-defined comment formats

Verification

  • Manual (required)
  • Automated

Manual verification completed:

  1. BlazorApp10 (Issue .Net 10 Blazor Enhanced Navigation in WASM fails due to no PageTitle #64522): Validated navigation between InteractiveServer pages with/without PageTitle components, and InteractiveWebAssembly pages. Multiple navigation cycles completed without errors.

  2. BugReportApp (Issue .NET 10 Blazor navigation from wasm to interactive server broken #64472): Validated navigation between InteractiveWebAssembly → InteractiveServer → InteractiveWebAssembly. Both directions work correctly with SignalR connections established properly.

Packaging changes reviewed?

  • Yes
  • No
  • N/A

This is a JavaScript/TypeScript code change only. No packaging changes required.


When servicing release/2.3

  • Make necessary changes in eng/PatchConfig.props

@github-actions github-actions bot requested a review from a team as a code owner November 25, 2025 17:52
@dotnet-policy-service dotnet-policy-service bot added the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Dec 3, 2025
@ilonatommy
Copy link
Copy Markdown
Member

/azp run

@ilonatommy ilonatommy removed the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Dec 5, 2025
@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 4 pipeline(s).

@PaulHuizer
Copy link
Copy Markdown

This regression issue is fixed but not released in the first service release?

@javiercn javiercn added the Servicing-consider Shiproom approval is required for the issue label Dec 10, 2025
@dotnet-policy-service dotnet-policy-service bot added the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Dec 17, 2025
@github-actions github-actions bot added the area-blazor Includes: Blazor, Razor Components label Feb 10, 2026
@aafvstam
Copy link
Copy Markdown

This is not fixed in 10.0.3, just tested it with this weeks build but still see the issue:

image

Any clue when this may arrive on .NET 10?

@hpansuria
Copy link
Copy Markdown

We are facing the exact same issue with our .net 8.0 upgrade to .net 10.0.3? Has this been released or still awaiting release? It will be good to get the clarity of the .net 10 version this fix is available on or going to be available on.

blazor.web.js:1 Uncaught (in promise) TypeError: Cannot read properties of null (reading 'insertBefore')
at q (blazor.web.js:1:22605)
at blazor.web.js:1:182534
at li (blazor.web.js:1:182543)
at si (blazor.web.js:1:179774)
at ai (blazor.web.js:1:181712)
at si (blazor.web.js:1:179337)
at ai (blazor.web.js:1:181712)
at si (blazor.web.js:1:179337)
at ai (blazor.web.js:1:181712)
at si (blazor.web.js:1:179337)

@rbhanda rbhanda added this to the 10.0.6 milestone Mar 3, 2026
@rbhanda rbhanda added Servicing-approved Shiproom has approved the issue and removed Servicing-consider Shiproom approval is required for the issue labels Mar 3, 2026
@lewing lewing merged commit d9eee00 into release/10.0 Mar 3, 2026
28 checks passed
@lewing lewing deleted the backport/pr-64529-to-release/10.0 branch March 3, 2026 18:28
@dotnet-policy-service dotnet-policy-service bot modified the milestones: 10.0.6, 10.0.4 Mar 3, 2026
@wtgodbe wtgodbe modified the milestones: 10.0.4, 10.0.5 Mar 4, 2026
@wtgodbe wtgodbe modified the milestones: 10.0.5, 10.0.6 Mar 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-blazor Includes: Blazor, Razor Components pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun Servicing-approved Shiproom has approved the issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants