Skip to content

Fix Blazor activity route correlation for per-page interactivity - #70063

Open
Yuvan111 wants to merge 21 commits into
dotnet:mainfrom
Yuvan111:fix-64554-routerper
Open

Yuvan111 wants to merge 21 commits into
dotnet:mainfrom
Yuvan111:fix-64554-routerper

Conversation

@Yuvan111

Copy link
Copy Markdown
Contributor

Fix Blazor activity route correlation for per-page interactivity

Description

Fixes missing route correlation on Blazor event activities when using per-page interactivity. Restores the aspnetcore.components.route tag and link to the corresponding navigation activity. Addresses #64554 without changing public APIs or rendering, navigation, and event-handler semantics.

Root Cause

Blazor stores navigation activity context in a renderer-local activity-link store. Per-page navigation runs in the static SSR renderer, while component events execute in a separate interactive renderer. The navigation context was not transferred, leaving event activities without route correlation while circuit correlation remained available.

Solution

Transfer navigation activity context and route tags through the existing persistent-state infrastructure. Restore context during interactive renderer initialization and refresh it after enhanced navigation. Preserve live interactive Router context and circuit links, while clearing stale route context and avoiding payloads when no listener exists.

Test Coverage

  • Unit tests cover restoration, context round trips, stale-state clearing, Router precedence, scope isolation, and WebAssembly lifetimes.
  • Browser tests cover Server, WebAssembly, and Auto initialization, prerendering options, enhanced navigation, and interactive Router controls.

Fixes #64554

@github-actions github-actions Bot added the area-blazor Includes: Blazor, Razor Components label Oct 27, 2026
@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Oct 27, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Thanks for your PR, @Yuvan111. Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@Yuvan111
Yuvan111 marked this pull request as ready for review October 30, 2026 07:00
Copilot AI balanced review requested due to automatic review settings October 30, 2026 07:00
@Yuvan111
Yuvan111 requested a review from a team as a code owner October 30, 2026 07:00

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The new activity-state wrapper registrations depend on an unregistered ComponentStatePersistenceManager, causing service-provider construction to fail with ValidateOnBuild for tracing-only custom renderer hosts.

1 open issue
What changed in this PR

This PR addresses #64554 by transferring Blazor navigation activity context from static server rendering to interactive renderers, restoring route tags and navigation links on per-page component events without changing public APIs.

Changes:

  • Persist and restore route activity context, clear stale correlation, and preserve interactive Router context.
  • Integrate activity-state persistence with renderer initialization and Server/WebAssembly service registration.
  • Add unit tests, browser scenarios, and telemetry collection for initialization and enhanced navigation.
File Description
src/​Shared/​Components/​ComponentsActivityLinkStore.cs Adds context lookup and removal.
src/​Components/​WebAssembly/​WebAssembly/​test/​Hosting/​WebAssemblyHostBuilderTest.cs Checks render-mode registration with tracing disabled.
src/​Components/​WebAssembly/​WebAssembly/​src/​Hosting/​WebAssemblyHostBuilder.cs Registers the WebAssembly activity-state render mode.
src/​Components/​WebAssembly/​Server/​src/​WebAssemblyRazorComponentsBuilderExtensions.cs Registers WebAssembly persistence support on the server.
src/​Components/​test/​testassets/​TestContentPackage/​ActivityLinksTestTrigger.razor Provides an interactive event trigger and runtime indicators.
src/​Components/​test/​testassets/​TestContentPackage/​ActivityLinksTestTelemetry.cs Defines shared activity telemetry records.
src/​Components/​test/​testassets/​TestContentPackage/​ActivityLinksInteractiveRouterPage.razor Hosts interactive Router test scenarios.
src/​Components/​test/​testassets/​TestContentPackage/​ActivityLinksInteractiveRouter.razor Supplies the interactive Router control.
src/​Components/​test/​testassets/​Components.WasmMinimal/​Program.cs Enables telemetry export for activity-link tests.
src/​Components/​test/​testassets/​Components.WasmMinimal/​Components.WasmMinimal.csproj Enables diagnostics and adds OpenTelemetry support.
src/​Components/​test/​testassets/​Components.WasmMinimal/​ActivityLinksWebAssemblyExporter.cs Sends browser activity telemetry to the test server.
src/​Components/​test/​testassets/​Components.TestServer/​RazorComponents/​Pages/​Interactivity/​ActivityLinksWebAssemblyNavigationTwo.razor Adds the WebAssembly navigation destination.
src/​Components/​test/​testassets/​Components.TestServer/​RazorComponents/​Pages/​Interactivity/​ActivityLinksWebAssemblyNavigationOne.razor Adds the WebAssembly navigation starting page.
src/​Components/​test/​testassets/​Components.TestServer/​RazorComponents/​Pages/​Interactivity/​ActivityLinksWebAssemblyLayout.razor Hosts a retained WebAssembly component.
src/​Components/​test/​testassets/​Components.TestServer/​RazorComponents/​Pages/​Interactivity/​ActivityLinksNavigationTwo.razor Adds the Server navigation destination.
src/​Components/​test/​testassets/​Components.TestServer/​RazorComponents/​Pages/​Interactivity/​ActivityLinksNavigationOne.razor Adds the Server navigation starting page.
src/​Components/​test/​testassets/​Components.TestServer/​RazorComponents/​Pages/​Interactivity/​ActivityLinksLayout.razor Hosts a retained Server component.
src/​Components/​test/​testassets/​Components.TestServer/​RazorComponents/​Pages/​Interactivity/​ActivityLinksCircuitInitialization.razor Exercises render modes and prerendering options.
src/​Components/​test/​testassets/​Components.TestServer/​RazorComponents/​ComponentsActivityTestCollector.cs Collects, samples, and exports test activities.
src/​Components/​test/​testassets/​Components.TestServer/​RazorComponentEndpointsStartup.cs Configures tracing and telemetry endpoints.
src/​Components/​test/​E2ETest/​ServerRenderingTests/​InteractivityTest.cs Adds browser assertions for route and circuit correlation.
src/​Components/​Server/​src/​DependencyInjection/​ServerRazorComponentsBuilderExtensions.cs Registers the Server activity-state render mode.
src/​Components/​Components/​test/​ComponentsActivityStateTest.cs Tests persistence, restoration, clearing, precedence, and lifetimes.
src/​Components/​Components/​src/​RenderTree/​Renderer.cs Initializes activity-state restoration for the renderer.
src/​Components/​Components/​src/​RegisterRenderingMetricsServiceCollectionExtensions.cs Registers activity-state adapters and persistence metadata.
src/​Components/​Components/​src/​PersistentState/​PersistentStateProviderServiceCollectionExtensions.cs Registers adapters even when tracing is disabled.
src/​Components/​Components/​src/​PersistentState/​ComponentStatePersistenceManager.cs Owns lazily initialized activity state.
src/​Components/​Components/​src/​ComponentsActivityState.cs Implements route-context capture and restoration.
src/​Components/​Components/​src/​ComponentsActivitySource.cs Exposes listener and navigation-activity state.

Review effort: Balanced

@PureWeen

PureWeen commented Nov 3, 2026

Copy link
Copy Markdown
Member

/review

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed frozen head 878e81f204c188df75569065db91ff4a8c42cf6e against trusted guidance commit ca7f6f3ffa5947a42939147890049ff5194c452c.

One validated P2 finding remains: removing a conditional interactive Router does not release route-context ownership, causing later SSR activity-state updates for the retained root to be discarded.

Both routed guide reviews completed (CrossCuttingGuidance and BlazorComponentsGuidance) with the configured gpt-5.6-sol workers. Existing feedback already covers thread-safe activity-state initialization, tracing-only DI registration, and clearing stale route state when tracing is disabled; none was republished. The duplicate keyed render-mode registration candidate was discarded because the only product consumer performs singular keyed resolution and no realistic changed behavior was established. No unresolved candidates remain.

Targeted validation used the supplied worktree at the frozen SHA. The pinned SDK installed successfully, but the targeted Components test build could not proceed because required generated Blazor Web.JS distribution assets were absent; this build limitation is unrelated to the source-validated finding. No temporary diagnostic test files were added. Security review was excluded by the trusted bundle; no other materially changed area was left without its routed guide.

Generated by ASP.NET Core Pull Request Review for #70063 · copilot · gpt56 · 388.7 AIC · ⌖ 12.3 AIC · ⊞ 20K
Comment /review to run again

@PureWeen PureWeen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two current-head issues remain after reconciling the hosted review and existing threads.

Human-directed and GitHub Copilot-generated.

@PureWeen

PureWeen commented Nov 4, 2026

Copy link
Copy Markdown
Member

/review

@PureWeen PureWeen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Round 2 review at 1e9cbeeaf6eaec4bbdd1e2de9ffe302887221ccd: one non-blocking telemetry metadata issue is noted below.

This finding is based on source and immutable contract verification; no browser/runtime reproduction is claimed.

Human-directed and GitHub Copilot-generated.

@PureWeen

PureWeen commented Nov 5, 2026

Copy link
Copy Markdown
Member

/review

@PureWeen PureWeen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Round 3 at a8456b1d40142e4ea8e6305554fe576395a9f874: one non-blocking P3 telemetry issue remains.

This finding is based on frozen-source/contract verification and a managed persistence probe, not a live SignalR/browser pause-resume run. The probe ran on an older installed preview runtime.

Human-directed and GitHub Copilot-generated.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Looks like this PR hasn't been active for some time and the codebase could have been changed in the meantime.
To make sure no conflicting changes have occurred, please rerun validation before merging. You can do this by leaving an /azp run comment here (requires commit rights), or by simply closing and reopening.

@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 Nov 12, 2026
@PureWeen

Copy link
Copy Markdown
Member

/review

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

A critical state-restoration bug can leave retained event handlers linked to a previous navigation, while process-wide listener races and uncontrolled Auto runtime selection undermine test reliability and coverage.

3 open issues
1 resolved since last review

Review effort: Balanced

@PureWeen

Copy link
Copy Markdown
Member

Round 4 local panel at d4afc4a41b4b6cd8c6a7fd666994b2d07b2ff10c: G and S returned no new findings; O retained one unresolved diagnostic. No verified/question finding remains for a new inline review. The hosted /review run completed with an explicit no-findings/noop result.

agent-reviewed-needs-changes remains because the current-head CCR threads 4635037695, 4635037765, and 4635037840 are still unresolved and non-outdated. This records their status, not a technical assessment of those comments.

Informational [UNRESOLVED]: src/Components/Components/src/RegisterRenderingMetricsServiceCollectionExtensions.cs:69 (also :84) adds unconditional keyed-service resolution on persistent-state setup. O traced the in-repository WebAssembly startup path and raised possible compatibility with ConfigureContainer providers that lack IKeyedServiceProvider. The native verifier returned DOWNGRADE/external: neither a concrete compatible third-party-container reproduction nor target-version-bound external behavior was established. This is not a confirmed startup regression.

Discarded diagnostics: The proposed Server/WASM restoration overwrite was ruled out by production store/render-mode filtering and SkipLastSnapshot. Routine negative checks also covered initialization ordering, live-Router ownership, unsampled route clearing, circuit-link preservation, registration/lifetimes, serialization metadata, and bounded telemetry polling. Auto-destination coverage and cross-test activity capture already have the linked existing comments, so they are not duplicated here.

Posted for informational purposes so the author can confirm the verifier didn't discard or leave unresolved a real finding; this item does not block agent-reviewed-approved.

Untested coverage limits: Both Auto destinations, restoration-before-retained-root-parameter-update ordering, browser delivery versus direct setter/store probes, the interactive-Router E2E guard's independent regression sensitivity, actual trimmed/AOT publication, and activity-listener race frequency were not established by execution. These are separate from the routine discarded checks and are not additional findings.

Validation boundary: All three arms reviewed frozen target source; no PR-head build, test, or browser validation ran. O ran an ancillary shared-framework DI probe, but deleted it without a retained target-bound artifact, so it is not credited as verification.

Human-directed and GitHub Copilot-generated.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Human architecture review is needed to confirm the renderer/scope lifetime contract and unconditional persistence registrations across mixed Server and WebAssembly lifetimes, Router ownership hand-off, and circuit snapshots.

No open issues 🎉

3 resolved since last review

Review effort: Balanced

@PureWeen

Copy link
Copy Markdown
Member

/review

@PureWeen

Copy link
Copy Markdown
Member

Copilot's local review panel found no issues to raise at this commit.

Informational [UNRESOLVED] diagnostics:

  • src/Components/Components/src/ComponentsActivityState.cs:121: G could not establish whether both activity-state wrappers restore during InitialValue in single-mode Interactive Server and overwrite the server-local route context. The verifier returned DROP/unestablished; its response also had a minor schema error.
  • src/Components/Components/src/ComponentsActivitySource.cs:51: S could not establish whether a same-URL Router parameter refresh can clear route correlation when the replacement Navigate activity is not sampled.
  • src/Components/Components/test/ComponentsActivityStateTest.cs:582: S could not establish whether the registration-restore test can pass with an empty serialized registration array.
  • src/Components/test/testassets/Components.TestServer/RazorComponents/ComponentsActivityTestCollector.cs:30: S found a conditional cross-scenario bucketing mechanism, but no current Selenium producer that overlaps distinct active IDs.

Posted for informational purposes so the author can confirm the verifier didn't discard or leave unresolved a real finding; this item does not block agent-reviewed-approved.

Untested coverage limits: The arms did not run the PR-head build, unit tests, browser tests, trimming/AOT publication, or a target-bound runtime repro. Additional source-only gaps included custom keyed-service-provider behavior, publish-time serialization metadata, enhanced-navigation delivery ordering, Auto enhanced-navigation coverage, and independent regression sensitivity of the interactive-Router E2E guard. The previously posted keyed-provider diagnostic was not duplicated.

Validation boundary: Three independent arms completed frozen-source review at 9fc1f066e5ba5b3241264bc5fbcc6e0755d9f94b; hosted /review run 45093141261 also completed with an explicit no-findings noop. No runtime or browser validation was credited.

Human-directed and GitHub Copilot-generated.

@kotlarmilos

Copy link
Copy Markdown
Member

Please keep this focused on restoring route correlation for per-page interactivity. Can we reduce the persistence changes and test infrastructure to what this fix needs? Please preserve stale-route clearing and existing Server, WebAssembly and interactive-router behavior.

@Yuvan111

Copy link
Copy Markdown
Contributor Author

@kotlarmilos , Simplified this to one renderer-owned route payload using existing persistence callbacks, removing duplicate wrappers, keyed registrations, and unnecessary telemetry test infrastructure. Preserved stale-route clearing and Server/WebAssembly/Auto and interactive-router behavior.

This branch was previously deployed

1 inactive (outdated) deployment
copilot-pat-pool — acffaf74 Deployed Oct 27, 2026 by dotnet-policy-service[bot] via pat_pool #1991
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-reviewed-approved area-blazor Includes: Blazor, Razor Components community-contribution Indicates that the PR has been added by a community member pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Blazor Activity links on global render vs per-page rendermode are totally different

6 participants