Skip to content

Commit 92ca7be

Browse files
committed
fix(web): harden split view from review findings
Focus now follows pointer activation across panes, so a preventDefault click can no longer leave terminal shortcuts acting on the wrong pane's terminal, and terminal ownership swaps in the same commit the secondary thread is picked or dropped. Dropped the hoisted diff worker pool: the pool is a module singleton, and mounting it at the route level spawned workers on the landing screen. The resize handle caches its bounds at pointerdown instead of forcing layout per move, and the split sheet no longer blurs the other pane. A disconnected or deleted environment gets a pane-local notice instead of a blank pane, the open-in-split picker waits for thread shells to hydrate, a lone image dialog keeps Escape from the inactive pane, and editors come only from the pane's own server. Review by gpt-5.6-sol and Claude Opus 5; fixes by Claude Fable 5 in Claude Code.
1 parent a5bff50 commit 92ca7be

9 files changed

Lines changed: 142 additions & 47 deletions

File tree

‎apps/web/src/components/ChatView.tsx‎

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,6 @@ import { useKnownTerminalSessions, useThreadRunningTerminalIds } from "../state/
282282
import { projectEnvironment } from "../state/projects";
283283
import { useEnvironmentQuery } from "../state/query";
284284
import {
285-
primaryServerAvailableEditorsAtom,
286285
primaryServerKeybindingsAtom,
287286
primaryServerSettingsAtom,
288287
serverEnvironment,
@@ -428,6 +427,7 @@ const EMPTY_ACTIVITIES: OrchestrationThreadActivity[] = [];
428427
const EMPTY_THREAD_MESSAGES: ReadonlyArray<OrchestrationMessage> = [];
429428
const EMPTY_PROVIDERS: ServerProvider[] = [];
430429
const EMPTY_PENDING_USER_INPUT_ANSWERS: Record<string, PendingUserInputDraftAnswer> = {};
430+
const EMPTY_PANE_AVAILABLE_EDITORS: never[] = [];
431431
function useDraftHeroLayoutTransition(isDraftHeroState: boolean) {
432432
const transitionGroupRef = useRef<HTMLDivElement | null>(null);
433433
const composerAnchorRef = useRef<HTMLDivElement | null>(null);
@@ -1317,6 +1317,13 @@ function ChatViewContent(props: ChatViewProps) {
13171317
state.splitMounted && state.secondaryRef !== null ? scopedThreadKey(state.secondaryRef) : null,
13181318
);
13191319
const threadSplitActive = splitSecondaryThreadKey !== null;
1320+
// Deliberately NOT mounted-gated like the key above: terminal ownership
1321+
// must swap in the same commit the secondary thread is picked or dropped,
1322+
// or both panes would attach the same terminal for a frame. While a picked
1323+
// split is not rendered this only costs a prewarmed hidden surface.
1324+
const splitReservedTerminalThreadKey = useThreadSplitStore((state) =>
1325+
state.secondaryRef !== null ? scopedThreadKey(state.secondaryRef) : null,
1326+
);
13201327
const updateProject = useAtomCommand(projectEnvironment.update, { reportFailure: false });
13211328
const upsertKeybinding = useAtomCommand(serverEnvironment.upsertKeybinding, {
13221329
reportFailure: false,
@@ -1831,15 +1838,17 @@ function ChatViewContent(props: ChatViewProps) {
18311838
// the secondary pane owns only its own thread's terminals and the
18321839
// primary pane owns everything else.
18331840
if (isSecondaryPane) return nextThreadKey === routeThreadKey;
1834-
return splitSecondaryThreadKey === null || nextThreadKey !== splitSecondaryThreadKey;
1841+
return (
1842+
splitReservedTerminalThreadKey === null || nextThreadKey !== splitReservedTerminalThreadKey
1843+
);
18351844
});
18361845
}, [
18371846
draftThreadKeys,
18381847
isSecondaryPane,
18391848
openTerminalThreadKeys,
18401849
routeThreadKey,
18411850
serverThreadKeys,
1842-
splitSecondaryThreadKey,
1851+
splitReservedTerminalThreadKey,
18431852
]);
18441853
const activeLatestTurn = activeThread?.latestTurn ?? null;
18451854
// Reading a finished thread clears the sidebar's Done badge. The visit is
@@ -2856,12 +2865,12 @@ function ChatViewContent(props: ChatViewProps) {
28562865
}),
28572866
);
28582867
const keybindings = useAtomValue(primaryServerKeybindingsAtom);
2859-
const primaryAvailableEditors = useAtomValue(primaryServerAvailableEditorsAtom);
2860-
// Editors must come from this thread's own environment — the primary
2861-
// server's list would offer/submit editor ids the pane's server may not
2862-
// have (visible with cross-environment split panes).
2868+
// Editors must come from this thread's own environment — another server's
2869+
// list would offer/submit editor ids this pane's server may not have
2870+
// (visible with cross-environment split panes). While the config is still
2871+
// unresolved, offering none beats offering a wrong list.
28632872
const paneServerConfig = serverConfigs.get(environmentId);
2864-
const availableEditors = paneServerConfig?.availableEditors ?? primaryAvailableEditors;
2873+
const availableEditors = paneServerConfig?.availableEditors ?? EMPTY_PANE_AVAILABLE_EDITORS;
28652874
// Prefer an instance-id match so a custom Codex instance (e.g.
28662875
// `codex_personal`) surfaces its own status/message in the banner rather
28672876
// than the default Codex's. Falls back to first-match-by-kind when no
@@ -7701,7 +7710,14 @@ function ChatViewContent(props: ChatViewProps) {
77017710
</RightPanelTabs>
77027711
) : null}
77037712
{shouldUseRightPanelSheet && rightPanelOpen && activeThreadRef ? (
7704-
<RightPanelSheet open onClose={closePreviewPanel}>
7713+
<RightPanelSheet
7714+
open
7715+
onClose={closePreviewPanel}
7716+
// While split, a blurred window-wide backdrop would hide the other
7717+
// pane — the panel stays modal, but the rest of the app stays
7718+
// legible and a click outside just dismisses it.
7719+
backdropClassName={threadSplitActive ? "bg-transparent backdrop-blur-none" : undefined}
7720+
>
77057721
<RightPanelTabs
77067722
mode="sheet"
77077723
// Same effective inset as the closed-state titlebar controls

‎apps/web/src/components/CommandPalette.tsx‎

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1658,10 +1658,16 @@ function OpenCommandPaletteDialog(props: {
16581658
if (openIntent?.kind !== "open-in-split") {
16591659
return;
16601660
}
1661+
if (allThreadItems.length === 0) {
1662+
// Thread shells may still be hydrating (cold load, environments still
1663+
// connecting) — hold the intent like the new-thread-in guard above and
1664+
// re-run when the list lands.
1665+
return;
1666+
}
16611667
if (openInSplitItems.length === 0) {
1662-
// Routine for one-thread setups (unlike the new-thread-in guard, which
1663-
// only trips with zero projects) — say so instead of silently opening
1664-
// the plain palette.
1668+
// Threads exist but every one is already on screen — routine for
1669+
// one-thread setups, so say so instead of silently opening the plain
1670+
// palette.
16651671
clearOpenIntent();
16661672
setOpen(false);
16671673
toastManager.add(
@@ -1688,7 +1694,15 @@ function OpenCommandPaletteDialog(props: {
16881694
},
16891695
],
16901696
});
1691-
}, [browseNavigation, clearOpenIntent, openInSplitItems, openIntent, pushPaletteView, setOpen]);
1697+
}, [
1698+
allThreadItems.length,
1699+
browseNavigation,
1700+
clearOpenIntent,
1701+
openInSplitItems,
1702+
openIntent,
1703+
pushPaletteView,
1704+
setOpen,
1705+
]);
16921706

16931707
const actionItems: Array<CommandPaletteActionItem | CommandPaletteSubmenuItem> = [];
16941708

‎apps/web/src/components/DiffWorkerPoolProvider.tsx‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ function DiffWorkerThemeSync({ themeName }: { themeName: DiffThemeName }) {
4646
}
4747

4848
export function DiffWorkerPoolProvider({ children }: { children?: ReactNode }) {
49-
const existingWorkerPool = useWorkerPool();
5049
const { resolvedTheme } = useTheme();
5150
const diffThemeName = resolveDiffThemeName(resolvedTheme);
5251
const workerPoolSize = useMemo(() => {
@@ -55,12 +54,6 @@ export function DiffWorkerPoolProvider({ children }: { children?: ReactNode }) {
5554
return Math.max(2, Math.min(6, Math.floor(cores / 2)));
5655
}, []);
5756

58-
// An ancestor already owns a pool (e.g. the split-view layout hosting two
59-
// ChatViews): reuse it instead of spawning a second worker fleet.
60-
if (existingWorkerPool) {
61-
return children;
62-
}
63-
6457
return (
6558
<WorkerPoolContextProvider
6659
poolOptions={{

‎apps/web/src/components/RightPanelSheet.tsx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export function RightPanelSheet(props: {
77
children: ReactNode;
88
open: boolean;
99
onClose: () => void;
10+
backdropClassName?: string | undefined;
1011
}) {
1112
return (
1213
<Sheet
@@ -22,6 +23,7 @@ export function RightPanelSheet(props: {
2223
showCloseButton={false}
2324
keepMounted
2425
className={RIGHT_PANEL_SHEET_CLASS_NAME}
26+
backdropClassName={props.backdropClassName}
2527
>
2628
{props.children}
2729
</SheetPopup>

‎apps/web/src/components/chat/ExpandedImageDialog.tsx‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,16 @@ export const ExpandedImageDialog = memo(function ExpandedImageDialog({
2525
useEffect(() => {
2626
const onKeyDown = (event: globalThis.KeyboardEvent) => {
2727
// Split view: two dialogs can be open (one per pane) — only the
28-
// active pane's dialog owns Escape and the arrow keys.
29-
if (!isThreadPaneActive(threadPaneId)) return;
28+
// active pane's dialog owns Escape and the arrow keys then. A lone
29+
// dialog keeps them even from the inactive pane: it covers the whole
30+
// window, so gating it off would strand a keyboard-undismissable modal
31+
// (reachable via mod+\ while the dialog is open).
32+
if (
33+
!isThreadPaneActive(threadPaneId) &&
34+
document.querySelectorAll("[data-expanded-image-dialog]").length > 1
35+
) {
36+
return;
37+
}
3038
if (event.key === "Escape") {
3139
event.preventDefault();
3240
event.stopPropagation();
@@ -58,6 +66,7 @@ export const ExpandedImageDialog = memo(function ExpandedImageDialog({
5866
role="dialog"
5967
aria-modal="true"
6068
aria-label="Expanded image preview"
69+
data-expanded-image-dialog
6170
>
6271
<button
6372
type="button"

‎apps/web/src/components/thread-split/ServerThreadPaneHost.tsx‎

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import ChatView from "../ChatView";
66
import { Button } from "~/components/ui/button";
77
import { openCommandPalette } from "../../commandPaletteBus";
88
import { useThreadDetail, useThreadShell, useThreadStatus } from "../../state/entities";
9+
import { useEnvironment, useEnvironments } from "../../state/environments";
910
import { useEnvironmentQuery } from "../../state/query";
1011
import { environmentShell } from "../../state/shell";
1112
import { resolveThreadRouteRenderState } from "../../threadRoutes";
@@ -54,8 +55,32 @@ export function ServerThreadPaneHost({ threadRef }: { threadRef: ScopedThreadRef
5455
status: serverThreadStatus,
5556
});
5657

57-
if (renderState === "missing") {
58-
return <ThreadPaneUnavailable />;
58+
const { isReady: environmentCatalogReady } = useEnvironments();
59+
const environment = useEnvironment(threadRef.environmentId);
60+
61+
if (renderState === "missing" || (environmentCatalogReady && environment === null)) {
62+
return (
63+
<ThreadPaneNotice
64+
title="Thread unavailable"
65+
description="This thread was deleted or its environment is gone."
66+
/>
67+
);
68+
}
69+
70+
// The route can lean on the sidebar's connection indicators; this pane has
71+
// no chrome of its own, so a never-bootstrapping environment must say so
72+
// instead of staying blank forever.
73+
if (
74+
renderState === "loading" &&
75+
environment !== null &&
76+
environment.connection.phase !== "connected"
77+
) {
78+
return (
79+
<ThreadPaneNotice
80+
title="Environment not connected"
81+
description={`Waiting for ${environment.label} to connect.`}
82+
/>
83+
);
5984
}
6085

6186
return (
@@ -74,21 +99,19 @@ export function ServerThreadPaneHost({ threadRef }: { threadRef: ScopedThreadRef
7499
);
75100
}
76101

77-
function ThreadPaneUnavailable() {
102+
function ThreadPaneNotice({ title, description }: { title: string; description: string }) {
78103
const closeSplit = useThreadSplitStore((state) => state.closeSplit);
79104
return (
80105
<div className="flex h-full min-h-0 flex-col items-center justify-center gap-3 bg-background p-6 text-center">
81-
<div className="text-sm font-medium text-foreground">Thread unavailable</div>
82-
<div className="max-w-64 text-sm text-muted-foreground">
83-
This thread was deleted or its environment is gone.
84-
</div>
106+
<div className="text-sm font-medium text-foreground">{title}</div>
107+
<div className="max-w-64 text-sm text-muted-foreground">{description}</div>
85108
<div className="flex items-center gap-2">
86109
<Button
87110
size="sm"
88111
variant="outline"
89112
onClick={() => openCommandPalette({ open: "open-in-split" })}
90113
>
91-
Choose thread…
114+
Choose thread...
92115
</Button>
93116
<Button size="sm" variant="ghost" onClick={closeSplit}>
94117
Close split

‎apps/web/src/components/thread-split/SplitThreadLayout.tsx‎

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ import type { ScopedThreadRef } from "@t3tools/contracts";
55

66
import { ComposerHandleContext, useComposerHandleContext } from "../../composerHandleContext";
77
import type { ChatComposerHandle } from "../chat/ChatComposer";
8-
import { DiffWorkerPoolProvider } from "../DiffWorkerPoolProvider";
98
import { useMediaQuery } from "../../hooks/useMediaQuery";
109
import { resolveThreadRouteRef } from "../../threadRoutes";
1110
import { ServerThreadPaneHost } from "./ServerThreadPaneHost";
1211
import { ThreadPaneContext } from "./threadPaneContext";
1312
import {
1413
clampSplitRatio,
1514
noteThreadPaneFocus,
15+
reclaimThreadPaneFocus,
1616
registerThreadPaneComposer,
1717
registerThreadPaneRoot,
1818
THREAD_SPLIT_MEDIA_QUERY,
@@ -31,9 +31,10 @@ const SINGLE_GRID_TEMPLATE_COLUMNS = "minmax(0, 1fr)";
3131
* Wraps the chat routes' content. The tree shape is identical whether the
3232
* split is open or closed — only the separator and the secondary pane mount
3333
* and unmount — so toggling the split never remounts the routed ChatView
34-
* (which would reload previews, terminals, and scroll positions). The shared
35-
* DiffWorkerPoolProvider up here also means both panes reuse one worker pool
36-
* instead of spawning one per ChatView.
34+
* instance. (Its right panel still remounts on toggle: the split forces the
35+
* sheet presentation, which lives in a different tree position than the
36+
* inline one.) No diff worker pool is hoisted here on purpose: the pool is a
37+
* module singleton, so both panes' ChatView-level providers already share it.
3738
*/
3839
export function SplitThreadLayout({ children }: { children: ReactNode }) {
3940
const secondaryRef = useThreadSplitStore((state) => state.secondaryRef);
@@ -67,9 +68,7 @@ export function SplitThreadLayout({ children }: { children: ReactNode }) {
6768
const splitOpen = secondaryRef !== null && isWideEnoughForSplit;
6869

6970
return (
70-
<DiffWorkerPoolProvider>
71-
<SplitThreadPanes secondaryRef={splitOpen ? secondaryRef : null}>{children}</SplitThreadPanes>
72-
</DiffWorkerPoolProvider>
71+
<SplitThreadPanes secondaryRef={splitOpen ? secondaryRef : null}>{children}</SplitThreadPanes>
7372
);
7473
}
7574

@@ -163,7 +162,10 @@ function ThreadPaneSection({
163162
data-thread-pane-id={paneId}
164163
data-active={isActive ? "true" : "false"}
165164
className="relative h-full min-h-0 min-w-0 outline-none"
166-
onPointerDownCapture={() => setActivePane(paneId)}
165+
onPointerDownCapture={() => {
166+
setActivePane(paneId);
167+
reclaimThreadPaneFocus(paneId);
168+
}}
167169
onFocusCapture={(event) => {
168170
setActivePane(paneId);
169171
noteThreadPaneFocus(paneId, event.target);
@@ -186,7 +188,15 @@ function SplitResizeHandle({
186188
containerRef: React.RefObject<HTMLDivElement | null>;
187189
}) {
188190
const setSplitRatio = useThreadSplitStore((state) => state.setSplitRatio);
189-
const dragStateRef = useRef<{ pointerId: number; ratio: number } | null>(null);
191+
const dragStateRef = useRef<{
192+
pointerId: number;
193+
ratio: number;
194+
// Captured once at pointerdown: reading getBoundingClientRect per
195+
// pointermove would force a synchronous layout of both panes on every
196+
// move, defeating the rAF write coalescing below.
197+
boundsLeft: number;
198+
boundsWidth: number;
199+
} | null>(null);
190200
const frameRef = useRef<number | null>(null);
191201

192202
const applyRatio = useCallback(
@@ -206,21 +216,26 @@ function SplitResizeHandle({
206216
className="relative z-40 h-full w-1 shrink-0 cursor-col-resize bg-border/60 hover:bg-primary/40 data-[dragging=true]:bg-primary/60"
207217
onPointerDown={(event) => {
208218
if (event.button !== 0) return;
219+
const container = containerRef.current;
220+
if (!container) return;
221+
const bounds = container.getBoundingClientRect();
222+
if (bounds.width <= 0) return;
209223
event.preventDefault();
210224
event.currentTarget.setPointerCapture(event.pointerId);
211225
event.currentTarget.dataset.dragging = "true";
212226
dragStateRef.current = {
213227
pointerId: event.pointerId,
214228
ratio: useThreadSplitStore.getState().splitRatio,
229+
boundsLeft: bounds.left,
230+
boundsWidth: bounds.width,
215231
};
216232
}}
217233
onPointerMove={(event) => {
218234
const dragState = dragStateRef.current;
219-
const container = containerRef.current;
220-
if (!dragState || dragState.pointerId !== event.pointerId || !container) return;
221-
const bounds = container.getBoundingClientRect();
222-
if (bounds.width <= 0) return;
223-
dragState.ratio = clampSplitRatio((event.clientX - bounds.left) / bounds.width);
235+
if (!dragState || dragState.pointerId !== event.pointerId) return;
236+
dragState.ratio = clampSplitRatio(
237+
(event.clientX - dragState.boundsLeft) / dragState.boundsWidth,
238+
);
224239
if (frameRef.current === null) {
225240
frameRef.current = window.requestAnimationFrame(() => {
226241
frameRef.current = null;
@@ -240,8 +255,9 @@ function SplitResizeHandle({
240255
}
241256
setSplitRatio(dragState.ratio);
242257
}}
243-
onPointerCancel={() => {
258+
onPointerCancel={(event) => {
244259
dragStateRef.current = null;
260+
delete event.currentTarget.dataset.dragging;
245261
if (frameRef.current !== null) {
246262
window.cancelAnimationFrame(frameRef.current);
247263
frameRef.current = null;

0 commit comments

Comments
 (0)