Repository navigation
Defer inactive browser pages across worktree switches - #19326
Conversation
Restore worktrees and tabs on demand instead of mounting the full tree. Only render active pages and those required by automation, mobile drivers, or remote viewers. Inactive panes stay deferred with persistent viewport slots so their webview guests survive chrome unmounts, reducing memory overhead when opening workspaces with many tabs.
Pages defer rendering until active, then retain state when inactive. Add recovery logic to restore guests evicted by workspace memory pressure when pages are reactivated.
- Browser panes and pages now unmount when their worktree transitions to inactive, except for pages claimed by automation/mobile/viewer consumers - Prevents unwanted restoration of all hidden browser tabs when switching between worktrees - Tests verify proper cleanup at scale and correct page lifecycle across worktree switches
Document previews use a fixed partition and should not be recreated when the profile changes. Only URL-based pages need their webviews destroyed and rebuilt with the new profile. Includes test coverage.
Pages created in the background now start with loading: false, since they don't own a guest until first shown. Only live guests can report loading status, so background tabs sit idle until activation triggers navigation.
Move webview registration to attachDocPreviewWebview before append, ensuring it's enrolled in drag passthrough before becoming hittable. When a document preview tab remounts mid-drag, the previous hook-based enrollment landed too late. Also refactor mountEligible into isBrowserPagePanePaintable for clarity.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
This PR stops Orca from restoring every browser tab on worktree activation or relaunch by deferring <webview> guest creation until a tab/page is first shown, then retaining it while its worktree stays active.
- Deferred inactive-tab mounting —
BrowserOverlaySlotnow wrapsBrowserPanein a newDeferredBrowserContentgate keyed onisPaintablewithretainMounted={isWorktreeActive}, so only the active tab (or a paint-retained one) mounts a guest while its viewport slot stays pinned. - Cold page creation —
buildBrowserPagenow setsloading: falseunconditionally, so background tabs no longer show a phantom spinner and navigate on first activation instead of eagerly. - Shared deferral gate —
DeferredBrowserContentcentralizes the "latch once mounted, retain while active" logic that was previously duplicated inRetainedBrowserPaneOverlayLayer. - Eviction-aware guest recovery —
validateRegistrationtreats a disconnected webview as evicted and rebuilds instead of retrying into a failure card. - Document previews join the registry — doc-preview webviews now register via
registerPersistentWebview(drag passthrough + eviction accounting), restore on reactivation, and survive profile switches since they use a fixed partition.
I traced the retention/deferral seam end to end (overlay slot → BrowserPane → per-page gate), the SSH routing gate's page-id change, the eviction-recovery path, and the doc-preview registry/remint flow. The deferral semantics (retain once mounted, drop on worktree deactivate) are coherent, the two non-overlay BrowserPane callers keep their old behavior via the isWorktreeActive default, and the new tests pin real behavior rather than tautologies.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Team Run ID: 📒 Files selected for processing (19)
💤 Files with no reviewable changes (1)
Included review availability: Your plan provides up to 10 included reviews per hour; 7 remain after this review. 📝 WalkthroughWalkthroughBrowser panes now use deferred mounting and retention based on paintability and worktree activity. Overlay slots remain retained while inactive panes are parked. Guest recovery handles disconnected webviews and restores selected evicted pages. Document previews register persistent guests, remint guests after eviction, and remain during profile changes. New tests cover lifecycle transitions, large workspaces, guest recovery, profile switching, and loading state initialization. Merge Risk: ⚪ Minimal · up to No actionable merge-blocking risk remains. 🚥 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 |
…ound pages Two defects from the same #19326 regression. Each is necessary; neither is sufficient. A 2x2 ablation is in the PR body. Missing publication edge: the offscreen guest policy notified the runtime on every navigation FAILURE path but not on a successful main-frame commit, so a page created blank and then navigated never invalidated the published snapshot. A pull (session.tabs.list) read the live WebContents and looked correct, while the pushed snapshot clients actually apply stayed at about:blank forever. Successful commit now uses the same worktree-scoped notifier the failure paths already use. Missing mount admission: #19326 deferred inactive browser pages behind a paintability gate; #19633 repaired that for local pages by admitting explicitly created ones, but scoped admission to local URL pages. A runtime-backed page opened in the background is never the active tab, has no local guest to retain, and was never admitted, so its pane never mounted. Document previews stay excluded. Guards are vitest, not e2e: e2e is not a required check in this repo.

ELI5
Browser tabs in inactive worktrees no longer wake up all at once. Orca creates a page only when it is needed, then releases inactive browser UI while retaining the state required to restore it when the user returns.
What Changed
loading: false) until a guest exists.Why
Opening or switching to a worktree with many browser tabs should not restore every hidden browser guest. This reduces unnecessary guest initialization and memory use while preserving active streaming and the state of pages that remain retained.
Linked Issue
N/A — standalone browser lifecycle improvement.
Visual Proof
Hidden Electron validation confirmed that the active tab rendered one webview while a second, inactive cold tab rendered none. The inactive tab remained visible in the tab strip without initializing a browser guest.
Testing
ORCA_BACKGROUND_LAUNCH=1 pnpm tc:webORCA_BACKGROUND_LAUNCH=1 pnpm test src/renderer/src/components/assemble-chrome/browser-deferred-lifecycle.test.tsx src/renderer/src/components/assemble-chrome/BrowserPaneOverlayLayer.test.tsx src/renderer/src/components/assemble-chrome/browser-workspace-pane.retention-props.test.tsx src/renderer/src/components/browser-pane src/renderer/src/hooks/ipc-events/browser-request-ipc-bridge.profile-switch.test.ts src/renderer/src/store/slices/browser.test.ts— 107 files / 861 tests passedORCA_BACKGROUND_LAUNCH=1 pnpm run check:code-quality:changedThe rendered activation/remount, worktree-return, and document-preview transitions were covered by automated tests; the bounded CDP run exercised the cold-tab behavior.
Review
Checklist