diff --git a/packages/app/perf/README.md b/packages/app/perf/README.md index c53e0fe6801..6dd23c2beec 100644 --- a/packages/app/perf/README.md +++ b/packages/app/perf/README.md @@ -9,7 +9,7 @@ build on the e2e mock server, so they need no backend. | --------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------ | | `timeline.bench.ts` | scroll history · type in composer · find in session · expand an edit · drag the review's edge | A 120-turn session of markdown, code, tools and diffs. | | `stream.bench.ts` | stream a reply · into a tool-heavy history · with review open · wait on a running session | 160 markdown deltas at 40 a second from a server that never waits. | -| `tabs.bench.ts` | switch tab (warm, review open, after a resize, 1,200 models) · open an unvisited tab (± review) | Two tabs of 200 long markdown exchanges each, loaded in full. | +| `tabs.bench.ts` | switch tab (warm, review open, after a resize, 1,200 models) · away and back with review open · open an unvisited tab (± review) | Two tabs of 200 long markdown exchanges each, loaded in full. | | `navigation.bench.ts` | Home → session · close the last tab · new session (Home, titlebar) · new session page in and out · child session · restore 8 tabs · activate a restored tab · command palette (session, Home) | The stress fixture, paginated, from a fresh document every run. | | `home.bench.ts` | load home · update a session in the background | 500, 5,000 and 10,000 root sessions across 12 folders. | | `review.bench.ts` | open review · filter files · next file | 100 and 10,000 changed files of 100 lines each. | diff --git a/packages/app/perf/tabs.bench.ts b/packages/app/perf/tabs.bench.ts index 6da2647f6ad..28de47e813b 100644 --- a/packages/app/perf/tabs.bench.ts +++ b/packages/app/perf/tabs.bench.ts @@ -65,6 +65,16 @@ const cases = { "switch tab": warm, // The review pane open on 72 changed files beside both timelines. "switch tab with review open": warm, + // Away from the session with the review open, to one with nothing beside it, and back: both directions a person + // pays when switching between them. + "switch away and back with review open": { + ...warm, + async run({ page, prepared }) { + await page.click(tab(prepared.target), { until: prepared.targetReady }) + await page.click(tab(prepared.source), { until: prepared.sourceReady }) + }, + reset: ({ page }) => page.idle(), + }, // The destination was laid out before the review pane narrowed the timeline, so it lays out again. "switch tab after review resized it": { ...warm, diff --git a/packages/app/src/runtime/plugin/panels.tsx b/packages/app/src/runtime/plugin/panels.tsx index c4ca26abbaf..1a63edac8e3 100644 --- a/packages/app/src/runtime/plugin/panels.tsx +++ b/packages/app/src/runtime/plugin/panels.tsx @@ -494,7 +494,10 @@ export function createRegion(input: { export type Region = ReturnType -/** Grouped content stays mounted while any member is listed; other tabs mount only while selected. */ +/** + * Grouped content stays mounted while any member is listed; other tabs mount only while selected, and the last one + * stays mounted, hidden, while the pane selects nothing. + */ export function RegionContent(props: { pane: RegionPane view: MountedSession @@ -505,12 +508,22 @@ export function RegionContent(props: { Array.from(new Set(props.pane.entries().flatMap((entry) => (entry.tab.group ? [groupKey(entry)] : [])))), ) - const single = createMemo(() => { + // A switch to a session with nothing open in this pane keeps the last tab, so switching back shows it again instead of + // tearing down and building a panel such as the review, its file tree and diffs, on every switch. Closing a tab in + // the same session still unmounts it. + const kept = createMemo<{ key: string | undefined; session: string }>((previous) => { const entry = props.pane.selected() + const session = props.view.key - return entry && !entry.tab.group ? entry.key : undefined + if (!entry && previous?.key && previous.session !== session) return previous + + return { key: entry && !entry.tab.group ? entry.key : undefined, session } }) + const single = () => kept().key + + const shown = () => props.pane.selected()?.key === single() + return ( <> @@ -582,9 +595,18 @@ export function RegionContent(props: { tabIndex={entry()?.tab.tabbable ? 0 : undefined} data-slot="tabs-content" class="flex flex-col h-full overflow-hidden contain-strict" + // Out of the pane's flow and skipped while hidden, so showing it again reuses its style and layout. + // Skipped content takes neither focus nor the pointer, and unlike `inert`, flipping it restyles + // nothing inside. + classList={{ "absolute inset-0 [content-visibility:hidden]": !shown() }} + aria-hidden={!shown() || undefined} > props.pane.openFor(plugin) }} + value={{ + ...props.frame, + visible: () => props.frame.shown() && shown(), + open: () => props.pane.openFor(plugin), + }} > {() =>