Skip to content

Avoid SectionRenderModeMismatch warning for PageTitle in default Blazor apps - #69832

Merged
kotlarmilos merged 27 commits into
dotnet:mainfrom
karmegams02:section_rendermode_warning
Nov 6, 2026
Merged

kotlarmilos merged 27 commits into
dotnet:mainfrom
karmegams02:section_rendermode_warning

Conversation

@karmegams02

@karmegams02 karmegams02 commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Description

Fix the SectionRenderModeMismatch warning emitted when visiting the Counter page in a Blazor Web App configured for per-page/component interactivity.

Root cause

App.razor contains a HeadOutlet rendered using static server-side rendering (SSR). HeadOutlet internally uses SectionOutlet, while the Counter page's PageTitle uses SectionContent.

The Counter page declares an interactive render mode selected by the template, so its PageTitle inherits that mode. This places SectionContent and SectionOutlet across different render-mode boundaries, triggering the warning during prerendering even though the constant title displays and the counter works.

Fix

Move the render-mode directive, counter markup, state, and event handling into a child CounterContent component. Keep PageTitle in Counter.razor outside the interactive boundary.

For per-page interactivity, PageTitle and HeadOutlet now both use static SSR, while CounterContent remains interactive. Preserve the existing implementation for global interactivity, update the sample and template baselines, and add a Chromium regression test checking counter interaction without the warning.

Test

The Chromium test runs a Blazor Web App with per-page Server interactivity, navigates to Counter, verifies that clicking the button increments the count, and checks that no section render-mode mismatch warning appears in the server output.

Fixes #69673

@github-actions github-actions Bot added the area-blazor Includes: Blazor, Razor Components label Oct 14, 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 14, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

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

@karmegams02 karmegams02 changed the title Section rendermode warning Avoid SectionRenderModeMismatch warning for PageTitle in default Blazor apps Oct 14, 2026
@karmegams02
karmegams02 marked this pull request as ready for review October 14, 2026 11:36
@karmegams02
karmegams02 requested review from a team and SamMonoRT as code owners October 14, 2026 11:36
Copilot AI balanced review requested due to automatic review settings October 14, 2026 11:36

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 warning’s static-rendering remediation is incorrect for interactive-outlet/static-content mismatches.

1 open finding
What changed in this PR

Improves Blazor head-section mismatch diagnostics and suppresses the expected default-template PageTitle warning.

Changes:

  • Adds descriptive built-in section identifiers.
  • Demotes static-outlet/interactive-title mismatches to Debug.
  • Adds render-mode coverage and documents the behavior.
File Description
SectionRegistry.cs Selects diagnostic severity and updates guidance.
HeadOutlet.cs Adds descriptive head-section identifiers.
EndpointHtmlRendererTest.cs Tests diagnostic behavior across render modes.
BlazorComponentsGuidance.md Documents the diagnostic policy and limitation.

🧠 Review effort: Balanced


💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

@dariatiurina

Copy link
Copy Markdown
Contributor

From what I see, this just downgrades this particular warning to Debug when PageTitle is used with a static HeadOutlet. It doesn't fix the problem; it hides the problem in the templates. In a globally interactive app, I can change PageTitle at runtime, and the tab title will update (e.g. developers use a “Please return to the page!” notification). With per-page interactivity and a static HeadOutlet, this will not work. The warning explains why. So the solution should lie in changing the templates or improving the warning instead of just hiding it.

karmegams02 and others added 2 commits October 23, 2026 14:42
This reverts commit aa076f3.

Revert "Addressed the review concerns."

This reverts commit 16915f4.

Revert "Fix render mode difference warning during navigation from Home (SSR) to Counter (Server) in Web App page per rendermode template"

This reverts commit 32ff938.
Keep Counter pages and PageTitle static for per-page interactivity and move interactive controls into child components. Preserve global interactivity and cover title navigation, reloads, and section mismatch diagnostics.

Fixes dotnet#69673

Co-authored-by: Copilot <[email protected]>
@karmegams02

Copy link
Copy Markdown
Contributor Author

Thanks @dariatiurina and @kotlarmilos for the guidance. I've revised the implementation to address the template's render-mode boundary rather than downgrade the framework warning.

This update supersedes the diagnostic/log-level approach described in the original PR description. The framework diagnostic changes have been removed, and section render-mode mismatch warnings remain unchanged.

Updated approach

For per-page interactivity, the generated Counter page now keeps its constant page title and heading in the static component tree. Only the counter state, button, and event handler move into a child component with the appropriate interactive render mode:

  • Server: Interactive Server
  • WebAssembly: Interactive WebAssembly
  • Auto: Interactive Auto

This keeps the page title and the static head outlet in the same render-mode boundary while preserving counter interactivity.

For global interactivity, the existing Counter implementation is retained, and the additional child component is excluded from generation. The per-page Blazor Web App sample has also been updated to follow the same pattern.

@PureWeen

PureWeen commented Nov 1, 2026

Copy link
Copy Markdown
Member

/review

@PureWeen

PureWeen commented Nov 1, 2026

Copy link
Copy Markdown
Member

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

@kotlarmilos

Copy link
Copy Markdown
Member

@karmegams02 I am not following the changes. How the razor page fixes the problem? PR description is too long and hard to read.

@karmegams02

Copy link
Copy Markdown
Contributor Author

@kotlarmilos , I’ve shortened the PR description and clarified how the change resolves the warning.

Previously, PageTitle inherited the Counter page’s interactive render mode, while HeadOutlet in App.razor used static SSR.

Moving @rendermode and the counter implementation into a child component leaves PageTitle outside the interactive boundary. PageTitle and HeadOutlet now both use static SSR, eliminating the mismatch while keeping the counter interactive.

@kotlarmilos kotlarmilos 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.

LGTM, thanks!

@kotlarmilos
kotlarmilos merged commit 1a03092 into dotnet:main Nov 6, 2026
32 checks passed
@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

✅ No documentation PR was created.

Confidence that documentation is needed: 30%

No docs needed: a bug fix restructuring the template Counter page to avoid a render-mode mismatch warning. A maintainer could optionally review whether any docs quote the template's Counter markup.

Documentation surfaces considered

  • Conceptual article: Not required — Template Counter page internals were restructured (CounterContent child component) to fix a spurious warning; no new user-facing feature or documented behavior changes.
  • Migration guidance: Not required — Existing apps need no action; the template change is a warning fix only.
  • Breaking change: Not required — No API removal, default change, or compatibility impact; existing apps are unaffected.

This branch was previously deployed

1 inactive deployment
copilot-pat-pool — f29d4379 Deployed Nov 6, 2026 by kotlarmilos via conclusion #213
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Default Blazor Web App emits SectionRenderModeMismatch warning for Counter PageTitle

5 participants