Skip to content

Use TagHelper components for MVC browser tools - #56072

Closed
javiercn wants to merge 2 commits into
javiercn-implement-gateway-hot-reloadfrom
javiercn-mvc-taghelper-browser-tools
Closed

javiercn wants to merge 2 commits into
javiercn-implement-gateway-hot-reloadfrom
javiercn-mvc-taghelper-browser-tools

Conversation

@javiercn

@javiercn javiercn commented Sep 1, 2026

Copy link
Copy Markdown
Member

Important

Stacked on and dependent on #56071. Review this PR against javiercn-implement-gateway-hot-reload; it contains only the incremental MVC/Razor Pages activation changes.

Summary

  • register an ITagHelperComponent from the existing browser-refresh hosting startup while browser tooling is active
  • append the existing external browser-tools script once, at the end of rendered <body> content through the built-in BodyTagHelper pipeline
  • disable generic response-stream rewriting for MVC/Razor Pages while retaining an explicit legacy fallback for hosted Blazor WebAssembly static index.html, including restart-only watch mode
  • document that built-in MVC/Razor Pages body TagHelpers activate automatically, while custom/static HTML requires user-provided activation

The existing hosting-startup and DeltaApplier process-loading paths remain separate. This change does not add YARP to MVC applications and does not implement build-time index.html rewriting.

Manual validation

Created a real Razor Pages app with the locally built .NET 11 SDK, then ran:

$redist='C:\Users\jacalvar\source\repos\copilot-worktrees\sdk\javiercn-fictional-succotash\artifacts\bin\redist\Debug\dotnet'
$app='C:\Users\jacalvar\.copilot\session-state\5219b316-5710-4504-97ae-244a45eb681e\files\mvc-taghelper-manual\App'
$env:DOTNET_ROOT=$redist
$env:DOTNET_MULTILEVEL_LOOKUP='0'
$env:DOTNET_WATCH_SUPPRESS_LAUNCH_BROWSER='1'
$env:ASPNETCORE_URLS='http://localhost:5017'
Push-Location $app
& "$redist\dotnet.exe" watch --no-launch-profile

Observed in a real browser:

  • Home and Privacy each rendered exactly one /_framework/aspnetcore-browser-refresh.js script, as the final <body> element; navigating layouts/pages did not duplicate it.
  • The browser-tools client loaded and connected.
  • Editing Pages\Index.cshtml updated the live heading to TagHelper browser refresh live!; watch logged C# and Razor changes applied in 1573ms and only one Now listening launch occurred, proving no restart.
  • The watched process retained the BrowserRefresh hosting startup and the separate BrowserRefresh/DeltaApplier startup hooks. Normal Razor Pages launch did not receive ASPNETCORE_AUTO_RELOAD_USE_LEGACY_HTML_INJECTION.

Then ran the app without tooling:

$env:ASPNETCORE_URLS='http://localhost:5018'
& "$redist\dotnet.exe" run --no-build --no-launch-profile

The page started and rendered with zero browser-refresh script tags and no browser-tools sentinel. The no-launch-profile Production run also reported an unrelated missing generated scoped-CSS development asset; that environment-only static-assets warning did not affect the activation checks. The external NuGet credential-provider workaround was not needed in this fork.

Automated validation

  • build.cmd
  • RunTests.cs --project test\Microsoft.AspNetCore.Watch.BrowserRefresh.Tests\Microsoft.AspNetCore.Watch.BrowserRefresh.Tests.csproj: 115 passed
  • RunTests.cs --project test\dotnet-watch.Tests\dotnet-watch.Tests.csproj --filter "FullyQualifiedName~BrowserRefreshServerTests|FullyQualifiedName~BlazorWebAssemblyAppModelTests": 18 passed

Boundaries

MVC and Razor Pages are automatic only when rendering executes the built-in body TagHelper. Static HTML, custom rendering that bypasses it, and hosted Blazor WebAssembly index.html are not covered by ITagHelperComponent; hosted Blazor WebAssembly keeps the existing stream fallback to prevent regression. Static/custom applications otherwise require explicit script activation. There is no build-time HTML rewriting in this change.

Design deviations: none.

@javiercn
javiercn requested review from a team, lbussell, mthalman and tmat as code owners September 1, 2026 15:36
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
2 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

Use the built-in BodyTagHelper component pipeline to append one external browser-tools script for supported net11 MVC and Razor Pages responses.

Behavior: changed: supported MVC and Razor Pages activate browser tooling without generic HTML rewriting

State: builds; regression coverage follows in the next commit

Review hint: the supported boundary is the TagHelper registration and body-only PostContent append; static HTML remains user-activated

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 49a13c60-1d66-4321-bfdb-01275ead89d6
Cover body-only script insertion, hosting-startup registration, legacy fallback, and app-model selection for the MVC/Razor Pages boundary.

Behavior: preserved

State: complete for PR #56072

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 49a13c60-1d66-4321-bfdb-01275ead89d6
@javiercn
javiercn force-pushed the javiercn-mvc-taghelper-browser-tools branch from 6a6eca8 to e9a9b46 Compare September 2, 2026 10:32
javiercn added a commit that referenced this pull request Sep 8, 2026
Cover body-only script insertion, hosting-startup registration, legacy fallback, and app-model selection for the MVC/Razor Pages boundary.

Behavior: preserved

State: complete for PR #56072

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 49a13c60-1d66-4321-bfdb-01275ead89d6
javiercn added a commit that referenced this pull request Sep 18, 2026
Cover body-only script insertion, hosting-startup registration, legacy fallback, and app-model selection for the MVC/Razor Pages boundary.

Behavior: preserved

State: complete for PR #56072

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 49a13c60-1d66-4321-bfdb-01275ead89d6
@github-actions

github-actions Bot commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

Due to lack of recent activity, this PR has been labeled as 'Stale'. It will be closed if no further activity occurs within 7 more days. Any new comment will remove the label.

@github-actions github-actions Bot added the stale label Nov 1, 2026
@github-actions github-actions Bot closed this Nov 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant