Skip to content

The agent that grows with you

fix(desktop): gate the kept-mounted hidden body on lifecycleKeepAlive

teknium1a0c61500bc41
diff --git a/apps/desktop/src/components/pane-shell/tree/renderer/pane-body.tsx b/apps/desktop/src/components/pane-shell/tree/renderer/pane-body.tsx
index 2e55c8658dd..5be46a7b215 100644
--- a/apps/desktop/src/components/pane-shell/tree/renderer/pane-body.tsx
+++ b/apps/desktop/src/components/pane-shell/tree/renderer/pane-body.tsx
@@ -1,4 +1,6 @@
-import { type ReactNode, useLayoutEffect, useRef, useState } from 'react'
+import { type ReactNode, useCallback, useRef, useState } from 'react'
+
+import { useResizeObserver } from '@/hooks/use-resize-observer'
interface PaneBodyProps {
hidden: boolean
@@ -12,25 +14,24 @@ export function PaneBody({ hidden, children }: PaneBodyProps) {
const ref = useRef<HTMLDivElement>(null)
const [size, setSize] = useState<{ width: number; height: number }>()
- useLayoutEffect(() => {
- const body = ref.current
-
- if (hidden || !body) {
- return
- }
-
- const observer = new ResizeObserver(entries => {
- const { width, height } = entries[0].contentRect
-
- if (width > 0 && height > 0) {
- setSize(previous => (previous?.width === width && previous.height === height ? previous : { width, height }))
+ // Rides the app's ONE shared observer (see use-resize-observer.ts); the
+ // hidden body is a fixed box, so only visible measurements are remembered.
+ const remember = useCallback(
+ (entries: readonly ResizeObserverEntry[]) => {
+ const rect = entries[0]?.contentRect
+
+ if (!hidden && rect && rect.width > 0 && rect.height > 0) {
+ setSize(previous =>
+ previous?.width === rect.width && previous.height === rect.height
+ ? previous
+ : { width: rect.width, height: rect.height }
+ )
}
- })
-
- observer.observe(body)
+ },
+ [hidden]
+ )
- return () => observer.disconnect()
- }, [hidden])
+ useResizeObserver(remember, ref)
return (
<div
diff --git a/apps/desktop/src/components/pane-shell/tree/renderer/tree-group.test.tsx b/apps/desktop/src/components/pane-shell/tree/renderer/tree-group.test.tsx
index e2e7142f9e8..773b720e697 100644
--- a/apps/desktop/src/components/pane-shell/tree/renderer/tree-group.test.tsx
+++ b/apps/desktop/src/components/pane-shell/tree/renderer/tree-group.test.tsx
@@ -4,6 +4,7 @@ import { afterEach, describe, expect, it, vi } from 'vitest'
import { registry } from '@/contrib/registry'
import { $tabStripDefault, setTabStripDefault } from '@/store/tabstrip-prefs'
+import { stubResizeObserver } from '@/test/jsdom'
import type { GroupNode } from '../model'
import { $treeDragging, NEW_SESSION_DRAG, SESSION_TILE_DRAG } from '../store'
@@ -191,6 +192,53 @@ describe('TreeGroup', () => {
})
})
+ it('hides a keep-alive pane through hide/restore while a plain pane still parks', () => {
+ const disposeBrowser = registry.register({
+ area: 'panes',
+ data: { lifecycleKeepAlive: true },
+ id: 'terminal',
+ title: 'Browser',
+ render: () => <input data-live-page defaultValue="original" />
+ })
+ const disposePlain = registry.register({
+ area: 'panes',
+ id: 'plain',
+ title: 'Plain',
+ render: () => <input data-plain-page defaultValue="original" />
+ })
+
+ disposePane = () => {
+ disposeBrowser()
+ disposePlain()
+ }
+
+ vi.stubGlobal('CSS', { escape: (value: string) => value })
+ stubResizeObserver()
+
+ const both: GroupNode = { ...terminalGroup(false), panes: ['terminal', 'plain'] }
+
+ render(<TreeGroup node={both} parentAxis="row" />)
+ // Activate the plain tab once so it enters the hot-hidden cache too.
+ render(<TreeGroup node={{ ...both, active: 'plain' }} parentAxis="row" />)
+ render(<TreeGroup node={both} parentAxis="row" />)
+ const page = container!.querySelector<HTMLInputElement>('[data-live-page]')!
+ page.value = 'unsaved page state'
+ expect(container!.querySelector('[data-plain-page]')).not.toBeNull()
+ expect(toggle('Hide')).not.toBeNull()
+
+ render(<TreeGroup node={{ ...both, minimized: true }} parentAxis="row" />)
+ // The guest stays mounted (same node, same state) but hidden and inert;
+ // the ordinary pane parks exactly as before.
+ expect(container!.querySelector('[data-live-page]')).toBe(page)
+ expect(page.closest('[data-pane-hidden]')?.hasAttribute('inert')).toBe(true)
+ expect(container!.querySelector('[data-plain-page]')).toBeNull()
+
+ render(<TreeGroup node={both} parentAxis="row" />)
+ expect(container!.querySelector('[data-live-page]')).toBe(page)
+ expect(page.value).toBe('unsaved page state')
+ expect(page.closest('[data-pane-hidden]')).toBeNull()
+ })
+
it('keeps a top-edge strip inside its panel and yields native drag while moving a pane', () => {
disposePane = registry.register({
area: 'panes',
diff --git a/apps/desktop/src/components/pane-shell/tree/renderer/tree-group.tsx b/apps/desktop/src/components/pane-shell/tree/renderer/tree-group.tsx
index 84d8764cd2a..c1958e6865e 100644
--- a/apps/desktop/src/components/pane-shell/tree/renderer/tree-group.tsx
+++ b/apps/desktop/src/components/pane-shell/tree/renderer/tree-group.tsx
@@ -343,6 +343,14 @@ export function TreeGroup({
const paneLifecycle = lifecycleRef.current.entries
const keptPanes = shown.filter(id => paneLifecycle[id] && paneLifecycle[id].lifecycle !== 'parked')
+ // HIDE ≠ CLOSE for stateful guests: a minimized zone keeps only its
+ // keep-alive panes mounted (the embedded Browser's <webview> would otherwise
+ // be destroyed and rebuilt on restore — fresh document, lost automation
+ // target). Every other pane parks on hide exactly as before.
+ const mountedPanes = node.minimized
+ ? keptPanes.filter(id => Boolean(paneChrome(paneFor(id)).lifecycleKeepAlive))
+ : keptPanes
+
// ONE header style: the app's compact pane-header. Whether this zone shows
// it is the resolver's call, not this component's — see strip-visibility.ts
// for the precedence. The same resolver answers for the toggle command, so
@@ -748,54 +756,58 @@ export function TreeGroup({
scroll positions and measurements survive the round-trip — which also
makes a hidden layer's rect identical to the visible one's, hence the
marker document-wide lookups filter on (see pane-visibility.ts). */}
- <PaneBody hidden={Boolean(node.minimized)}>
- {isEmpty ? (
- <div className="grid h-full place-items-center">
- {/* Same decode primitive as the CONNECTING boot overlay. */}
- <DecodeText className="text-(--ui-text-quaternary)" cursor prefix={1} text="HERMES" />
- </div>
- ) : (
- keptPanes.map(paneId => {
- const pane = paneFor(paneId)
- const isActive = paneId === activeId && !node.minimized
-
- return (
- <div
- aria-hidden={!isActive || undefined}
- className={cn('absolute inset-0 overflow-auto', !isActive && 'pointer-events-none invisible')}
- inert={!isActive || undefined}
- key={paneId}
- {...hiddenPaneProps(!isActive)}
- >
- {pane?.render ? (
- // Visibility flows to the pane so a kept-alive chat surface
- // can gate its hot (per-token) subscriptions while hidden;
- // the group id identifies the ZONE it lives in, for state
- // that is per-zone rather than per-tab (composer pop-out).
- // The reload epoch keys the CONTENT, not this layer: a
- // Reload remounts the contribution (effects re-run, state
- // resets) while the layer — and every other tab — stays.
- <PaneGroupContext.Provider value={node.id}>
- <PaneLifecycleContext.Provider value={isActive ? 'visible' : 'hot-hidden'}>
- <PaneVisibleContext.Provider value={isActive}>
- <ContribBoundary id={pane.id} key={paneEpochs[paneId] ?? 0}>
- <ContribRender render={pane.render} />
- </ContribBoundary>
- </PaneVisibleContext.Provider>
- </PaneLifecycleContext.Provider>
- </PaneGroupContext.Provider>
- ) : (
- isActive && (
- <div className="p-3 font-mono text-[11px] text-(--ui-text-quaternary)">
- {t.zones.missingPane(paneId)}
- </div>
- )
- )}
- </div>
- )
- })
- )}
- </PaneBody>
+ {(!node.minimized || mountedPanes.length > 0) && (
+ <PaneBody hidden={Boolean(node.minimized)}>
+ {isEmpty ? (
+ <div className="grid h-full place-items-center">
+ {/* Same decode primitive as the CONNECTING boot overlay. */}
+ <DecodeText className="text-(--ui-text-quaternary)" cursor prefix={1} text="HERMES" />
+ </div>
+ ) : (
+ mountedPanes.map(paneId => {
+ const pane = paneFor(paneId)
+ const isActive = paneId === activeId && !node.minimized
+
+ return (
+ <div
+ aria-hidden={!isActive || undefined}
+ className={cn('absolute inset-0 overflow-auto', !isActive && 'pointer-events-none invisible')}
+ inert={!isActive || undefined}
+ key={paneId}
+ {...hiddenPaneProps(!isActive)}
+ >
+ {pane?.render ? (
+ // Visibility flows to the pane so a kept-alive chat surface
+ // can gate its hot (per-token) subscriptions while hidden;
+ // the group id identifies the ZONE it lives in, for state
+ // that is per-zone rather than per-tab (composer pop-out).
+ // The reload epoch keys the CONTENT, not this layer: a
+ // Reload remounts the contribution (effects re-run, state
+ // resets) while the layer — and every other tab — stays.
+ <PaneGroupContext.Provider value={node.id}>
+ <PaneLifecycleContext.Provider
+ value={node.minimized ? 'hot-hidden' : (paneLifecycle[paneId]?.lifecycle ?? 'visible')}
+ >
+ <PaneVisibleContext.Provider value={isActive}>
+ <ContribBoundary id={pane.id} key={paneEpochs[paneId] ?? 0}>
+ <ContribRender render={pane.render} />
+ </ContribBoundary>
+ </PaneVisibleContext.Provider>
+ </PaneLifecycleContext.Provider>
+ </PaneGroupContext.Provider>
+ ) : (
+ isActive && (
+ <div className="p-3 font-mono text-[11px] text-(--ui-text-quaternary)">
+ {t.zones.missingPane(paneId)}
+ </div>
+ )
+ )}
+ </div>
+ )
+ })
+ )}
+ </PaneBody>
+ )}
{/* Edit-mode veil: the BODY is a drag handle for the active pane. It
starts below the header so tabs/headers stay directly interactive
diff --git a/website/docs/user-guide/desktop.md b/website/docs/user-guide/desktop.md
index d369c621dcb..a4aaf34ff50 100644
--- a/website/docs/user-guide/desktop.md
+++ b/website/docs/user-guide/desktop.md
@@ -49,6 +49,7 @@ The center of the app. You get:
- **Independent background drafts** — hidden chat tabs can update their drafts without moving the caret or selection in the visible composer.
- **Directive chip actions** — hover an actionable reference (such as a URL) to reveal its action pill. A short grace period lets you move from the chip to the pill before it dismisses. The pill stays available while you move within it; after leaving, unrelated pointer movement does not delay dismissal. Clicking its action preserves the draft selection.
- **A right-hand preview rail** — render web pages, files, and tool outputs side by side while you keep chatting.
+- **Hide vs. Close for the in-app browser** — a zone holding a Browser (or HTML preview) offers **Hide** instead of Minimize. Hiding collapses the zone to its restore rail but keeps the live page mounted: unsaved form input, timers, scroll position, and the agent's `drive_preview` automation target all survive, and **Restore** shows the same document without a reload. The hidden page is inert — it never takes keyboard shortcuts or steals composer focus. **Close** (the tab's ×) is what actually releases the page.
- **Comment mode in the in-app browser** — click **Annotate** in the preview browser bar, then click any element (or drag a box) on the live page and type a note; each saved comment stays as a numbered pin on the page. Saving a pin never sends a turn — when you're done, **Add N comments** attaches a cropped screenshot per pin and a short prompt naming each comment to the composer, and you still hit send yourself. Each element comment carries its CSS selector, its markup, and the computed styles that matter for layout, so the agent can find the element in your source instead of guessing from the picture. Password and hidden field values, and any attribute that looks like a key or token, are redacted on the page before the markup leaves it. Larger batches arrive grouped by which part of the page each comment sits in, so twenty-odd comments become a handful of pieces of work rather than one task each — and because the groups are separate DOM subtrees they usually touch separate files, which is what makes handing them to parallel workers safe. Pin numbers hold steady if you delete one, and switching chats clears the stack.
- **Composer history and queue editing** — press the up/down arrow keys in an empty composer to recall and reuse previous prompts, and edit messages you've queued up before they're sent. Pressing Stop (or Esc) while turns are queued pauses the queue and expands it above the composer; resume it from there, or send, edit, and delete individual entries.
- **Task progress above the composer** — expand the Tasks header to inspect each phase. Long lists stay bounded above the input; scroll inside the expanded list to reach the final tasks without moving the conversation.