Repository navigation
fix(browser): keep browser tabs rendering across worktree switches (STA-3228) - #12137
Conversation
…TA-3228) Switching away from a worktree that had a targeted background mount unmounted BrowserPaneOverlayLayer, pulling the persistent <webview> slots out of the DOM and killing their guests; the stale viewport cache then kept rendering into the removed subtree, so the tab stayed blank forever and reload threw. Keep the overlay mounted for hidden worktrees (slots park their panes, so this stays cheap) and rebuild cached viewports whose slot root remounted.
Greptile SummaryFixes two layered defects that caused browser pane tabs to go permanently blank after switching worktrees and back: (1)
Confidence Score: 5/5Safe to merge — renderer-only change, no IPC, no partitions, no auth paths, no platform-conditional code touched. Both fixes are well-scoped and each edge case (parked state, stable root, replacement root, suspended-before-commit latch) has a dedicated unit test. The preserveViewport flag is narrowly applied only on the parent-drift path where a new viewport was already placed before teardown fires. Files Needing Attention: No files require special attention; all changed files have matching test coverage and clear inline rationale comments.
|
| Filename | Overview |
|---|---|
| src/renderer/src/components/browser-pane/BrowserPaneOverlayLayer.tsx | Adds RetainedBrowserPaneOverlayLayer — a memo wrapper that latches hasCommittedMount via useLayoutEffect after the first eligible DOM commit, keeping BrowserPaneOverlayLayer mounted for hidden worktrees. |
| src/renderer/src/components/browser-pane/browser-page-viewport.ts | ensureBrowserPageViewport now detects when existing.shell.parentElement differs from the registered root, removes the stranded shell, and rebuilds under the new root. |
| src/renderer/src/components/browser-pane/browser-page-webview.ts | Passes preserveViewport:true to destroyPersistentWebview on parent-drift teardown, preventing the freshly-rebuilt viewport shell from being removed while the stale webview is cleaned up. |
| src/renderer/src/components/browser-pane/webview-registry.ts | Adds optional preserveViewport flag to destroyPersistentWebview, skipping removeBrowserPageViewport on both the no-webview and live-webview paths when set. |
| src/renderer/src/components/Terminal.tsx | Replaces conditional BrowserPaneOverlayLayer mount with RetainedBrowserPaneOverlayLayer while leaving EmulatorPaneOverlayLayer on the old gating. |
| src/renderer/src/components/browser-pane/browser-page-viewport.test.ts | Adds three new regression tests covering cached-viewport reuse, parked viewport preservation, and rebuild under a replacement root. |
| src/renderer/src/components/browser-pane/BrowserPaneOverlayLayer.test.tsx | Adds tests for RetainedBrowserPaneOverlayLayer: deferred-then-retained lifecycle and suspended-before-commit does not latch hasCommittedMount. |
| src/renderer/src/components/browser-pane/BrowserPane.webview-preferences.test.ts | Adds test verifying destroyPersistentWebview is called with preserveViewport:true on parent-drift and the replacement container is connected with the new webview. |
Reviews (3): Last reviewed commit: "fix(browser): latch overlay retention af..." | Re-trigger Greptile
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe retained browser overlay mounts after a worktree becomes eligible and remains mounted when eligibility later becomes false. Emulator overlay mounting remains conditional. Cached browser page viewports are reused for the current root, preserved when no root exists, and rebuilt under replacement roots. Parent-drifted webviews preserve their viewports during teardown and mount in resolved replacement containers. Tests cover overlay retention, viewport cache behavior, and webview rebuilding. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/renderer/src/components/browser-pane/browser-page-viewport.test.ts (1)
67-83: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winExercise the stale-shell removal branch directly.
oldRoot.remove()runs beforeensureBrowserPageViewport, sostale.shell.isConnectedis alreadyfalsewhen the changed code runs. The test verifies replacement allocation, but it does not prove thatexisting.shell.remove()removes a shell still attached to the old root. Keep the old root connected until after the call, or add a second case for that condition.Suggested test adjustment
- oldRoot.remove() - registerBrowserOverlaySlotViewport('workspace-1', null) const newRoot = mountSlotViewport('workspace-1') + expect(oldRoot.contains(stale.shell)).toBe(true) const rebuilt = ensureBrowserPageViewport('page-1', 'workspace-1') + expect(oldRoot.contains(stale.shell)).toBe(false) expect(rebuilt).not.toBeNull()
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 32a65abb-21ad-4646-ba97-b930d396c0a7
📒 Files selected for processing (3)
src/renderer/src/components/Terminal.tsxsrc/renderer/src/components/browser-pane/browser-page-viewport.test.tssrc/renderer/src/components/browser-pane/browser-page-viewport.ts
There was a problem hiding this comment.
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: cce226c9-3872-488b-95a7-0dc22d27e4af
📒 Files selected for processing (7)
src/renderer/src/components/Terminal.tsxsrc/renderer/src/components/browser-pane/BrowserPane.webview-preferences.test.tssrc/renderer/src/components/browser-pane/BrowserPaneOverlayLayer.test.tsxsrc/renderer/src/components/browser-pane/BrowserPaneOverlayLayer.tsxsrc/renderer/src/components/browser-pane/browser-page-viewport.tssrc/renderer/src/components/browser-pane/browser-page-webview.tssrc/renderer/src/components/browser-pane/webview-registry.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- src/renderer/src/components/browser-pane/browser-page-viewport.ts
| const ensuredWebview = ensureBrowserPageWebview({ | ||
| browserTabId: 'browser-page-1', | ||
| container: replacementContainer, | ||
| inputLocked: false, | ||
| webviewPartition: 'persist:orca-browser', | ||
| resolveContainer | ||
| }) | ||
|
|
||
| expect(registryMocks.destroyPersistentWebview).toHaveBeenCalledWith('browser-page-1', { | ||
| preserveViewport: true | ||
| }) | ||
| expect(ensuredWebview?.container).toBe(replacementContainer) | ||
| expect(replacementContainer.isConnected).toBe(true) | ||
| expect(replacementContainer.lastElementChild).toBe( | ||
| ensuredWebview?.webview as unknown as Element | ||
| ) |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Use a distinct resolved container in this test.
The test passes replacementContainer as both container and the resolveContainer() result. An implementation that ignores resolveContainer() would still pass. Pass a separate requested container and assert that the new webview mounts in replacementContainer.
Proposed test update
+ const requestedContainer = createContainer('requested')
+
const ensuredWebview = ensureBrowserPageWebview({
browserTabId: 'browser-page-1',
- container: replacementContainer,
+ container: requestedContainer,
inputLocked: false,
webviewPartition: 'persist:orca-browser',
resolveContainer
})
+ expect(resolveContainer).toHaveBeenCalledTimes(1)
expect(ensuredWebview?.container).toBe(replacementContainer)📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| const ensuredWebview = ensureBrowserPageWebview({ | |
| browserTabId: 'browser-page-1', | |
| container: replacementContainer, | |
| inputLocked: false, | |
| webviewPartition: 'persist:orca-browser', | |
| resolveContainer | |
| }) | |
| expect(registryMocks.destroyPersistentWebview).toHaveBeenCalledWith('browser-page-1', { | |
| preserveViewport: true | |
| }) | |
| expect(ensuredWebview?.container).toBe(replacementContainer) | |
| expect(replacementContainer.isConnected).toBe(true) | |
| expect(replacementContainer.lastElementChild).toBe( | |
| ensuredWebview?.webview as unknown as Element | |
| ) | |
| const requestedContainer = createContainer('requested') | |
| const ensuredWebview = ensureBrowserPageWebview({ | |
| browserTabId: 'browser-page-1', | |
| container: requestedContainer, | |
| inputLocked: false, | |
| webviewPartition: 'persist:orca-browser', | |
| resolveContainer | |
| }) | |
| expect(resolveContainer).toHaveBeenCalledTimes(1) | |
| expect(registryMocks.destroyPersistentWebview).toHaveBeenCalledWith('browser-page-1', { | |
| preserveViewport: true | |
| }) | |
| expect(ensuredWebview?.container).toBe(replacementContainer) | |
| expect(replacementContainer.isConnected).toBe(true) | |
| expect(replacementContainer.lastElementChild).toBe( | |
| ensuredWebview?.webview as unknown as Element | |
| ) |
Electron QA — STA-3228 (b2dc29c)Validated the final pushed revision in an isolated Orca dev profile attached to the intended worktree through CDP.
Rendered after switching away and backReload still works after the returnMobile emulator QA is not applicable: this PR only changes desktop renderer/browser-webview paths. |
…12191) The parent-drift repair path (destroyPersistentWebview with preserveViewport: true, introduced in #12137) tears down and rebuilds the webview under the same browserTabId, but unconditionally forgot the tab's explicit user zoom. BrowserPane then re-seeds from the Settings default on the next mount, silently resetting per-tab zoom. Only forget explicit zoom on a real close; a preserveViewport rebuild keeps the same logical tab, so its zoom must survive.
…TA-3228) (stablyai#12137) * fix(browser): keep browser tabs rendering across worktree switches (STA-3228) Switching away from a worktree that had a targeted background mount unmounted BrowserPaneOverlayLayer, pulling the persistent <webview> slots out of the DOM and killing their guests; the stale viewport cache then kept rendering into the removed subtree, so the tab stayed blank forever and reload threw. Keep the overlay mounted for hidden worktrees (slots park their panes, so this stays cheap) and rebuild cached viewports whose slot root remounted. * fix(browser): retain live overlay slots without background churn * fix(browser): latch overlay retention after commit
…tablyai#12191) The parent-drift repair path (destroyPersistentWebview with preserveViewport: true, introduced in stablyai#12137) tears down and rebuilds the webview under the same browserTabId, but unconditionally forgot the tab's explicit user zoom. BrowserPane then re-seeds from the Settings default on the next mount, silently resetting per-tab zoom. Only forget explicit zoom on a real close; a preserveViewport rebuild keeps the same logical tab, so its zoom must survive.


Summary
Fixes STA-3228: a browser tab that was open in a worktree went permanently blank after switching to another worktree and back — the URL bar still showed the address, but the page area rendered nothing, and reload silently did nothing.
Two layered defects:
WorktreeSplitSurfaceunmountedBrowserPaneOverlayLayerfor hidden worktrees whenever a targeted background mount restriction existed (agent wake/resume sets one constantly). Unmounting the overlay pulls the persistent<webview>slot divs out of the DOM, and Electron destroys the guest the moment a<webview>leaves the DOM — defeating the design from fix(browser): keep webview guests alive across worktree switches #6408 that renders browser panes at worktree level precisely so guests survive switches.ensureBrowserPageViewportreturned the cached viewport shell even after its slot root had been unmounted, so when the worktree came back, the webview subtree was never re-appended to the live DOM. The tab stayed blank forever and the reload button threwThe WebView must be attached to the DOM and the dom-ready event emitted before this method can be called(observed in the renderer console during repro).Fix:
BrowserPaneOverlayLayermounted for hidden worktrees. Slots already park their pane subtrees when the worktree is hidden (shouldMountPane), so a background-woken worktree only pays for empty slot divs.EmulatorPaneOverlayLayerkeeps the old gating — it doesn't use the persistent-slot pattern.ensureBrowserPageViewportdetect a replaced slot root and drop the stranded shell so the caller rebuilds against the live root. This also self-heals any remaining path that unmounts slots (cross-worktree tab moves, surface eviction): the existing parent-drift check inensureBrowserPageWebviewthen rebuilds the webview, turning "blank forever" into "reloads once".Screenshots
Repro on main (tab created, worktree switched away and back — blank, reload dead):
Same sequence with the fix (guest survives without reloading — same in-page JS timestamp, no new HTTP request; reload button works):
Testing
pnpm lint(oxlint + react-doctor changed-lines on touched files)pnpm typecheckpnpm test(browser-pane suite 32 files/191 tests;Terminalsubstring sweep 462 files/5156 tests)pnpm buildNew tests in
browser-page-viewport.test.ts: cached-viewport reuse under a stable root, parked viewport preserved while the root is unregistered, and rebuild under a replacement root (asserts the stale shell is detached and the rebuilt shell is connected to the new root).Live Electron QA (dev build, CDP): reproduced the blank pane + dead reload on unfixed code, then verified with the fix that (a) slot/shell/webview stay in the DOM while the worktree is hidden, (b) the page renders after switching back with the guest's state intact (unchanged in-page timestamp, no new server request), (c) reload issues a real request, and (d) a session-restored tab renders after app restart.
AI Review Report
Reviewed the mount-gating change for perf regressions (background wakes previously skipped the overlay): slots park pane subtrees for hidden worktrees, so no webview guests or BrowserPane chrome mount from this change alone. Reviewed the viewport self-heal for interactions with
destroyPersistentWebview(which removes the current viewport beforeresolveContainerrebuilds it) and the floating-panel slot registration (FloatingBrowserSlotmints new tab ids, so no cross-host root swap for a live id). Checked the no-root case keeps returning the parked viewport so hidden-state callers see unchanged behavior. Cross-platform: renderer-only DOM/React change, no shortcuts, labels, paths, or shell behavior touched; nothing platform-conditional on macOS/Linux/Windows is affected.Security Audit
No input handling, command execution, path handling, auth, secrets, or dependency changes. No new IPC: the change only alters when existing renderer components mount and how a renderer-side DOM cache invalidates. Webview partitions are untouched (partition mismatch still forces a rebuild via the pre-existing check in
ensureBrowserPageWebview).Notes
EmulatorPaneOverlayLayermay have an analogous issue on the same conditional; left untouched to keep this PR scoped (worth a separate look).