Fix auto-pause when circuit starts after enhanced navigation - #68540
Fix auto-pause when circuit starts after enhanced navigation#68540surya3655 wants to merge 2 commits into
Conversation
f3834ec to
8fa28e8
Compare
|
Thanks for your PR, @surya3655. Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
There was a problem hiding this comment.
Pull request overview
This PR fixes Blazor Server AutoPause not activating when interactivity (circuit start) happens only after enhanced navigation from an initially static page. It ensures the server-emitted browser configuration discovered during enhanced navigation is merged into the circuit options before server startup initializers run, and updates the AutoPause initializer to handle both the “web” and “server” options shapes consistently.
Changes:
- Add an enhanced-navigation hook to observe the newly received HTML document and re-merge server-emitted browser configuration into existing startup options.
- Defer final circuit option resolution until server startup so configuration discovered later (during enhanced navigation) is included.
- Update AutoPause JS initializer to read configuration from either
options.circuit(web-start shape) or directly fromoptions(server-start shape), with new test coverage (unit + E2E).
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/Components/Web.JS/src/Services/NavigationEnhancement.ts | Adds a documentReceived callback so consumers can inspect the parsed HTML document before DOM sync. |
| src/Components/Web.JS/src/Boot.Web.ts | Merges browser configuration on initial load and on enhanced navigation (via documentReceived) so late-discovered config is applied. |
| src/Components/Web.JS/src/Boot.Server.Common.ts | Defers resolving circuit options until server startup, allowing enhanced-navigation config merges to be reflected when the circuit starts. |
| src/Components/test/testassets/Components.TestServer/RazorComponents/App.razor | Adds query-controlled browser configuration emission for AutoPause to support E2E validation scenarios. |
| src/Components/test/E2ETest/ServerRenderingTests/BlazorWebJsInitializersTest.cs | Adds an E2E regression test covering circuit start after enhanced navigation from a static page and verifying pauseCircuit is invoked. |
| src/Components/Server.AutoPause/src/js/test/AutoPauseInitializer.test.ts | Adds a unit test validating server-start configuration enables AutoPause even if web-start config didn’t. |
| src/Components/Server.AutoPause/src/js/autopause.lib.module.ts | Reads AutoPause configuration from either options shape and exports a real beforeServerStart handler. |
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
8fa28e8 to
a115017
Compare
Description
Blazor auto-pause is not activated when the circuit starts after enhanced navigation from an initially static (non-interactive) page. Hiding the tab does not pause the circuit, and the SignalR connection stays active.
This change re-discovers the server-emitted browser configuration at circuit start and makes the auto-pause initializer tolerant of both options shapes, so auto-pause activates consistently whether the interactive page is reached on initial load or through enhanced navigation.
Root Cause
The circuit starts lazily — only when the first interactive Server/Auto component is discovered, which for a static-first page happens during enhanced navigation, after the web initializers have already run. Three things then compound:
<!--Blazor-Configuration:...-->comment was present, so they never carried the auto-pause settings.options.circuit, which isundefinedon the server startup path whereCircuitStartOptionsis passed directly — so even correct configuration would not have been read.Result:
beforeServerStartreceived stale (or unreadable) configuration,configwas never set, andAutoPauseManagerwas never created — so novisibilitychangelistener was registered.Output
Before
Screen.Recording.2026-08-14.194642.mp4
After
Screen.Recording.2026-08-14.192435.mp4
Test Output
Fix Details
src/Components/Web.JS/src/Boot.Server.Common.tsstartServerCore, before the server initializers run.src/Components/Server.AutoPause/src/js/autopause.lib.module.tsafterWebStarted/afterServerStartedalready dispose any previous manager before creating a new one, so re-configuration at circuit start cannot accumulate listeners.Tests
AutoPauseInitializer.test.ts—server start reads auto-pause configuration discovered during enhanced navigation: with no configuration at web start no listener is registered; supplying configuration at server start registers exactly one.BlazorWebJsInitializersTest.cs—ServerInitializerActivatedAfterEnhancedNavigationFromStaticPage: loads a static page (assertingBlazor.pauseCircuitisundefined), enhanced-navigates to an interactive page, then dispatchesvisibilitychangeand assertspauseCircuitis invoked exactly once.Verified by reverting the source changes locally: both tests fail.
Notes
Boot.Web.tsuses on the initial startup path.beforeServerStartwould still read the wrong options shape on the classic Blazor Server path. Handling it at circuit start fixes both.Fixes #68337.