Skip to content

fix(overlay): keep a page that reconnects in a background tab alive - #457

Merged
erkamyaman merged 1 commit into
mainfrom
fix/overlay-hidden-reconnect
Nov 7, 2026
Merged

erkamyaman merged 1 commit into
mainfrom
fix/overlay-hidden-reconnect

Conversation

@erkamyaman

@erkamyaman erkamyaman commented Nov 7, 2026 •

Copy link
Copy Markdown
Member

What and why

Found in an audit of the implicit state machines in the overlay's visibility and reconnect handling (overlay.ts).

A page that reconnects while its tab is hidden can expire on the server.

  • When the link drops, leave() stops the refresher and clears the hidden heartbeat.
  • On reconnect, resendConfig() calls onVisibility(), whose hidden branch started with if (!refresher) return;.
  • With the tab still hidden, the page therefore never reported hidden: true, never started the 60 s hidden heartbeat, and kept its heartbeat paused.
  • The server's page TTL (rpc/page-ttl.ts, unlimited while hidden or beating) no longer covered it, so the page and its data could expire while the tab was in the background. The same happened after a bfcache pageshow in a hidden tab.

The hidden branch now checks whether the page is already marked hidden (stillHidden), not whether the refresher runs, and both places that clear stillHidden reset it.

A second drop during reconnect restarted everything while offline. overlay-link.ts marks the link online before restored, and the overlay's restored handler awaits claim-page and the redaction config. If the link dropped again in between, leave() ran first, and then resendConfig() still restarted the heartbeat, refresher and collectors offline. A drops counter now makes the handler stand down; the next restored picks up.

How it was verified

  • New overlay-reconnect-visibility.test.ts:
    • "reports a page that reconnects in a background tab as hidden and keeps it marked": the page reports hidden: true, sends hidden beats over 130 s, runs no refresher, and resumes normally when visible.
    • "stays quiet when the link drops again while the page is being claimed": no refresher runs while offline.
  • overlay-visibility.test.ts: "keeps a hidden tab marked when it comes back from the back/forward cache still hidden"
  • Each test fails with its fix removed and passes with it
  • pnpm test:devtools: 3661 passed
  • pnpm typecheck, pnpm format:check, pnpm commit:check

No docs change: the behaviour now matches what the docs already describe.


Generated by Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Fixed DevTools visibility reporting for pages that reconnect while hidden or are restored from the back/forward cache.
    • Hidden pages now avoid unnecessary component-tree updates and change detection until they become visible.
    • Fixed recovery after connection interruptions so monitoring resumes only after the page reconnects successfully.

When the link dropped, `leave()` stopped the refresher. On reconnect,
`onVisibility()` returned early in its hidden branch because the
refresher was gone, so a page still in a background tab never reported
itself hidden and never started its hidden heartbeat. The server could
then expire it and drop its data. The hidden branch now checks whether
the page is already marked hidden instead.

A second drop during the `restored` calls (claim-page, redaction) no
longer restarts the heartbeat, refresher and collectors while offline:
the handler stands down when the link dropped again in between.
@github-actions github-actions Bot added the area: package The ng-devtools package (packages/ng-devtools) label Nov 7, 2026
@coderabbitai

coderabbitai Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The overlay now tracks hidden-page status across visibility changes and checks for intervening connection drops during reconnect recovery. New tests cover hidden-page reporting, component-tree collection, and watcher behavior during connection outages.

Changes: Overlay visibility and reconnect

Layer / File(s) Summary
Hidden-page visibility state
packages/devtools/src/overlay.ts, packages/devtools/src/__tests__/overlay-visibility.test.ts, packages/devtools/src/__tests__/overlay-reconnect-visibility.test.ts
The overlay tracks whether it has reported the page as hidden, clears that state when visibility returns or the page leaves, and reports hidden status when needed. Tests check hidden reporting and verify that hidden pages do not push component trees or run active watchers.
Reconnect recovery checks
packages/devtools/src/overlay.ts, packages/devtools/src/__tests__/overlay-reconnect-visibility.test.ts
The overlay counts connection drops and skips applying fetched redaction or resending configuration if another drop occurs during recovery. Tests cover a drop while claim-page is pending and verify that watchers resume after a later successful claim.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Possibly related PRs

Suggested labels: area: package

Merge Risk: Minimal · up to c0291

No actionable issue is established; the change is mergeable after normal checks.

Pre-merge checks: Passed 5

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title describes the main change: keeping a hidden page alive after reconnection.
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 1 functions across 3 files.

Finishing Touches

Generate docstrings

  • Commit to this branch
  • Create a new PR
Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b794ed44-dc69-4859-94ac-38837adc1311
Commits

Reviewing files that changed from the base of the PR and between a7cb0c6 and c0291d6.

Files selected for processing: 3

  • packages/devtools/src/__tests__/overlay-reconnect-visibility.test.ts
  • packages/devtools/src/__tests__/overlay-visibility.test.ts
  • packages/devtools/src/overlay.ts

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@cloudflare-workers-and-pages

Copy link
Copy Markdown

🚀 Deploying Preview to Cloudflare 🚀

Preview Deployments by commit

Status Deployment URL Commit Updated (UTC) See this deployment's details
  • Build: Failed ❌

View logs ↗
c0291d6 2026-11-07T12:00:21.121Z View logs ↗

@nx-cloud

nx-cloud Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit c0291d6

Command Status Duration Result
nx affected -t test build ✅ Succeeded 1m 1s View ↗
nx build --configuration development ✅ Succeeded 36s View ↗

💡 Verify your cache is correct by running tasks in a sandbox. Read docs ↗


☁️ Nx Cloud last updated this comment at 2026-11-07 12:01:22 UTC

@erkamyaman erkamyaman mentioned this pull request Nov 7, 2026
5 tasks done

Copy link
Copy Markdown
Member Author

The one red check, "Workers Builds: angular-devtools", isn't from this PR. It's a leftover Cloudflare Worker build that fails on every PR and on main (#431). No fix exists in the repo because it lives in the Cloudflare dashboard. Every other check is green.


Generated by Claude Code

@erkamyaman
erkamyaman merged commit 3927cb2 into main Nov 7, 2026
12 of 13 checks passed
@erkamyaman
erkamyaman deleted the fix/overlay-hidden-reconnect branch November 7, 2026 12:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: package The ng-devtools package (packages/ng-devtools)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant