feat(desktop): port browser pane to v2 workspaces with global persistence
Summary
- Ports the v1 browser pane (webview, URL toolbar, history, autocomplete, error overlay, new-window handler) into v2 workspaces as a native implementation, using
@superset/panesidioms (runtime registry +ctx.actions.updateData+renderToolbarslot). v1 is untouched. - Introduces a float-over webview architecture: every
<webview>lives atdocument.body > #browser-runtime-rootand is positioned via aResizeObserveron a per-pane placeholder div. The element never reparents, so Electron's guestWebContentssurvives tab switches, workspace route remounts, and pane drags — no page reloads, no lost state, ever. - Adds a keep-alive tab rendering mode to
@superset/panes: visited tabs stay mounted behindvisibility: hiddenso their React state survives tab switches. Benefits every stateful pane kind (terminal scrollback, chat subscriptions, editor state). - Single-pane browser tabs show the page favicon + live page title in the tab bar via a new optional
renderTabLabelprop.
Why / Context
The v2 workspace previously registered a browser pane kind with a placeholder <iframe> stub. Porting v1's real implementation surfaced a fundamental Electron issue: reparenting a <webview> element via appendChild destroys its guest WebContents and reloads the page. v1 works around this with a "park in hidden container on unmount / reclaim on remount" pattern — but every reparent triggers the reload (v1 even has a // e.g. after DOM reparenting comment in its dom-ready handler re-registering the new webContentsId).
For v2, where tab switches, pane drags, and workspace switches all cause React subtrees to unmount and remount, the only correct answer is don't reparent at all. Float-over is that guarantee.
How It Works
browserRuntimeRegistry (module-level singleton, modeled on terminalRuntimeRegistry):
- Lazily appends a zero-sized,
pointer-events: none#browser-runtime-rootdiv todocument.body. - Each paneId maps to an entry holding the
<webview>element (child of root container), per-pane runtime state, and aResizeObserver. attach(paneId, placeholder, initialUrl, onDidStopLoading): creates the webview on first call (appended once, forever), stores the placeholder ref, starts aResizeObserveron it, and rAF-schedules an initialupdateLayout.updateLayout(entry): readsplaceholder.getBoundingClientRect()and writes the result to the webview's fixed-positiontop/left/width/height.detach: stops the observer and hides the webview. Does NOT reparent, does NOT remove.setVisibility(paneId, visible): driven byBrowserPane's subscription toactiveTabId === ctx.tab.id, toggles the webview's CSS visibility so inactive-tab webviews don't paint on top of the current tab.destroy: the only path that removes the webview from the DOM. Called from a single diff effect inpage.tsxthat walks all tabs' browser pane ids each render — anything that disappeared since the previous render gets destroyed. Correctly handles tab closes, intra-tab split closes, and pane drags between tabs (moved panes stay in the current set under their new tab, so they're not destroyed).
Keep-alive in packages/panes: Workspace.tsx tracks mountedTabIds and renders every visited tab into an absolute-stacked container. The active tab is fully interactive; inactive visited tabs use invisible pointer-events-none. BrowserPane doesn't unmount on tab switch, so usePersistentWebview's cleanup never runs, so the webview never even gets a chance to move.
Registry subscription pattern: to avoid the @trpc/react-query single-shared-React-context gotcha where workspaceTrpc.Provider hijacks electronTrpc React hooks inside v2 routes, every Electron-router call goes through the imperative electronTrpcClient proxy (matching the v2 TerminalPane pattern). All registry mutations/queries/subscriptions use .mutate(...) / .query(...) / .subscribe(...) directly — no useMutation / useQuery / useSubscription for electronTrpc.browser.* or electronTrpc.browserHistory.*.
Manual QA Checklist
Browser pane basics
- Create a browser tab → blank-page placeholder renders
- Type a URL → navigates, tab title + favicon update live
- Back/forward buttons work
- URL autocomplete shows history suggestions
- Error overlay appears for unreachable URLs
- Overflow menu (screenshot, hard reload, copy URL, clear cookies/history)
- DevTools button opens detached DevTools window
Global persistence (the main win)
- Scroll into a page → switch to another tab → return → scroll position preserved, no network refetch
- Type into a form → switch tab → return → input preserved
- Open browser in workspace A → switch to workspace B → return to A → webview untouched, no reload
Tab bar
- Single-pane browser tabs show favicon + live page title
- Multi-pane tabs fall back to default title
- Favicon updates across navigations without flicker
- No rounded corners on favicons
- Missing/broken favicons show no icon (no Globe fallback)
Split panes
- Split a browser pane → two independent webviews, each tracks its own state
- Resize the split handle → webview snaps smoothly via ResizeObserver
- Close one half → its webview is destroyed, other unaffected
Other pane kinds (benefit from keep-alive)
- Terminal scrollback survives tab switches
- Chat pane subscriptions stay open across tab switches
Destroy paths
- Close a browser tab → webview removed from
#browser-runtime-root - Close one half of a browser split → only that webview destroyed
- Drag a pane to another tab → moved pane survives (not destroyed by the diff effect)
Known Limitations
- Dropping panes onto another browser pane's body does not register. The Electron
<webview>compositor layer intercepts drag events at its painted position regardless ofpointer-events: none,visibility: hidden, or moving the element off-screen. Drops on pane headers still work. Deferred for a follow-up that likely involves patching@superset/panesto portal the drop target overlay above the webview, or moving the pane's drop target to a dedicated element. - Cross-workspace dev server preview is broken. For remote/relay-tunneled workspaces,
http://localhost:3000resolves to the renderer machine, not the host. No port-proxy route exists on the host-service or relay yet. Out of scope; browser panes work correctly for local workspaces. A future/proxy/:port/*route + a last-mile URL rewrite inusePersistentWebviewis the planned path. - Modal z-index with webviews. Float-over webviews paint on their own compositor layer and may bleed through modal backdrops depending on stacking context. Not observed in the tested flows but worth watching during review.
Testing
bun run typecheck(25 packages) ✓bun run lint✓bunx sherif✓bun test— 2389 pass / 3 pre-existing failures unrelated to this work (teardown.test.ts,setup.test.ts— git worktree fixture issues;useOrderedSections.test.tsx— pre-existingelectronTrpcClientinit-order bug in test env; none touch browser pane or panes library files)- Manual testing in
bun dev
Design Decisions
- Float-over instead of park-and-reclaim. Electron
<webview>reparenting is fundamentally broken for state preservation. Float-over guarantees no reparenting and is the only reliable solution. - Keep-alive tab rendering in the library, not just for browsers. Even with float-over,
BrowserPaneneeds to stay mounted on tab switch so its subscription toactiveTabIdkeeps the webview visible at the right moments. Keep-alive also benefits every other stateful pane for free. electronTrpcClientimperative calls inside v2.@trpc/react-querystores its context as a module singleton, soworkspaceTrpc.Providerinside v2 routes hijacks everyelectronTrpc.*React hook. Using the imperative proxy sidesteps the issue. Canonical precedent: v2TerminalPanedoes the same.- Diff effect as single source of truth for destroy. An earlier version of the destroy logic used an
onTabRemovedcallback that received the removed tab's old snapshot — which broke pane drags between tabs, because the moved pane was still in the old snapshot's panes record and got destroyed right as the target tab tried to attach it. The current pane-id diff correctly handles moves. - No
faviconUrlfallback icon. Tabs without a favicon show just the title, no Globe icon.
Follow-ups
- Fix drop-onto-browser-pane-body (library-level change to portal the drop target above the webview, or restructure to keep the drop target element on top of the float-over webview).
- Host-service
/proxy/:port/*+ renderer URL rewrite for dev server previews on remote workspaces. - Consider wiring up the v2
devtoolspane kind (currently still a stub).
Summary by cubic
Ports the browser pane to v2 workspaces with a float‑over Electron webview and global persistence. Removes keep‑alive tabs; persistence now comes from a registry that keeps each webview alive across tab switches, drags, and workspace remounts.
-
New Features
- Native v2 browser pane: webview lives under
#browser-runtime-rootand is positioned viaResizeObserver(no reparenting, no reloads). - URL bar with back/forward/reload, history autocomplete, error overlay, overflow menu, and DevTools.
- Live tab titles and favicons for single‑pane browser tabs via
getTabTitle+renderTabIcon; favicons persist across restarts. - Navigation improvements: back/forward use native webview history (keeps scroll/form/BFCache) with live canGoBack/Forward; stricter URL sanitization (auto scheme, localhost, search fallback); clears stale favicons on load; avoids redundant history writes on back/forward.
- New browser panes start at
about:blank.
- Native v2 browser pane: webview lives under
-
Migration
@superset/panesWorkspace adds optionalrenderTabIcon,getTabTitle, and a newonRemoved(pane)hook. Workspace renders only the active tab; browser cleanup usesonRemovedto call the runtime registry’sdestroy.BrowserPaneData: removemode; add optionalpageTitleandfaviconUrl; defaulturlisabout:blank.
Summary by CodeRabbit
-
New Features
- Full browser pane with navigation (Back/Forward/Reload), URL bar with autocomplete, error overlay with retry, DevTools access, and overflow menu (copy URL, screenshot, hard reload, clear data).
- Browser tabs now show page titles and favicons; URL suggestions dropdown included.
-
Changes
- New browser tabs now open to a blank page by default.