From 90c26c6e83fe64e29f9e7bb17940e99f5cdc75d0 Mon Sep 17 00:00:00 2001 From: Neil <4138956+nwparker@users.noreply.github.com> Date: Mon, 1 Jun 2026 19:34:12 -0700 Subject: [PATCH] Fix browser state across workspace switches (#4431) --- .../browser-pane/BrowserPaneOverlayLayer.test.tsx | 5 +++-- .../browser-pane/BrowserPaneOverlayLayer.tsx | 12 +++++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/renderer/src/components/browser-pane/BrowserPaneOverlayLayer.test.tsx b/src/renderer/src/components/browser-pane/BrowserPaneOverlayLayer.test.tsx index 2611dc10f..a385b61ee 100644 --- a/src/renderer/src/components/browser-pane/BrowserPaneOverlayLayer.test.tsx +++ b/src/renderer/src/components/browser-pane/BrowserPaneOverlayLayer.test.tsx @@ -65,10 +65,11 @@ describe('BrowserPaneOverlayLayer', () => { expect(markup).toContain('data-browser-pane-active="false"') }) - it('unmounts browser panes when their worktree is not visible', () => { + it('keeps the selected browser pane mounted but inactive when its worktree is not visible', () => { const markup = renderOverlay({ isWorktreeActive: false }) - expect(markup).not.toContain('data-browser-pane-id="browser-a"') + expect(markup).toContain('data-browser-pane-id="browser-a"') + expect(markup).toContain('data-browser-pane-active="false"') expect(markup).not.toContain('data-browser-pane-id="browser-b"') }) }) diff --git a/src/renderer/src/components/browser-pane/BrowserPaneOverlayLayer.tsx b/src/renderer/src/components/browser-pane/BrowserPaneOverlayLayer.tsx index 8d582fce6..eeec96953 100644 --- a/src/renderer/src/components/browser-pane/BrowserPaneOverlayLayer.tsx +++ b/src/renderer/src/components/browser-pane/BrowserPaneOverlayLayer.tsx @@ -28,6 +28,7 @@ type BrowserOverlaySlotProps = { // present in `browserTabs` but not referenced by any group's unified-tab // list). See the fallback branch below for why these slots remain hidden. groupId: string | undefined + isSelectedInGroup: boolean isActive: boolean // Why: the legacy architecture rendered BrowserPane inside TabGroupPanel, so // React events from the pane bubbled through TabGroupPanel's @@ -49,6 +50,7 @@ type BrowserOverlaySlotProps = { const BrowserOverlaySlot = memo(function BrowserOverlaySlot({ browserTab, groupId, + isSelectedInGroup, isActive, onFocusOwningGroup }: BrowserOverlaySlotProps): React.JSX.Element { @@ -59,6 +61,7 @@ const BrowserOverlaySlot = memo(function BrowserOverlaySlot({ : [browserTab.activePageId ?? browserTab.id] ) const isPaintable = isActive || automationVisible + const shouldMountBrowserPane = isSelectedInGroup || automationVisible // Why: each overlay pins itself to the owning TabGroupPanel's body via CSS // anchor positioning. `anchor()` resolves top/left relative to the viewport, // and the overlay's own `position: absolute` inside a positioned ancestor @@ -108,9 +111,11 @@ const BrowserOverlaySlot = memo(function BrowserOverlaySlot({ onFocusCapture={handleFocus} > {/* Why: inactive BrowserPane subtrees keep Electron guest renderers alive. - Unmounting parks the webview in the registry, where eviction enforces - the small recent-tab cap; automation-visible panes stay paintable. */} - {isPaintable ? : null} + The selected tab for each mounted worktree stays mounted even while + hidden so user DOM state (form text, scroll, SPA state) survives + workspace switches. Non-selected tabs still park unless automation + needs them paintable. */} + {shouldMountBrowserPane ? : null} ) }) @@ -190,6 +195,7 @@ const BrowserPaneOverlayLayer = memo(function BrowserPaneOverlayLayer({ key={browserTab.id} browserTab={browserTab} groupId={assignment?.groupId} + isSelectedInGroup={Boolean(assignment?.isActiveInGroup)} isActive={isActive} onFocusOwningGroup={focusOwningGroup} />