The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 22, 22:00 UTC
fix(web): terminal drawer no longer pushes the composer into the header (#19072)
Co-authored-by: Ryan Wible <197168665+rywible@users.noreply.github.com> Co-authored-by: Julius Marminge <julius0216@outlook.com> Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
Ryan Wible committed
Oct 19, 2026 at 23:11 UTC
055a8418c12bb9d170b231583ddc2fa7d98af687
6 files changed
+175
-28
apps/web/src/components/ChatView.tsx
+46
-2
@@ -1414,6 +1414,9 @@ export default function ChatView(props: ChatViewProps) {
1414
const [composerTimelineInset, setComposerTimelineInset] = useState(0);
1415
const [composerOverlayHeight, setComposerOverlayHeight] = useState(0);
1416
const composerTimelineInsetRef = useRef(0);
1417
+ const [composerReservedHeight, setComposerReservedHeight] = useState(0);
1418
+ const composerReservedHeightRef = useRef(0);
1419
+ const composerExpandedHeightRef = useRef(0);
1420
const composerRestingRef = useRef(false);
1421
const composerMountedRef = useRef(true);
1422
const [scrollToEndClearance, setScrollToEndClearance] = useState(0);
@@ -4751,6 +4754,28 @@ export default function ChatView(props: ChatViewProps) {
4754
composerTimelineInsetRef.current = nextInset;
4755
setComposerTimelineInset(nextInset);
4756
}
4757
+ // The terminal drawer and the empty placeholder lay out against the
4758
+ // expanded composer. The timeline inset already holds it through the
4759
+ // desktop resting row; remembering it while the mobile strip is collapsed
4760
+ // keeps both still when focus moves between the composer and the
4761
+ // terminal, instead of re-clamping the drawer against each intermediate
4762
+ // composer height. A collapsed strip can still grow (approvals, tasks), so
4763
+ // the reservation follows it up. A hero composer's overlay fills the pane,
4764
+ // so only its stack counts there.
4765
+ const stack = composerOverlayElement?.querySelector<HTMLElement>(
4766
+ '[data-chat-composer-stack="true"]',
4767
+ );
4768
+ const expandedComposerHeight =
4769
+ isDraftHeroState && stack ? Math.ceil(stack.getBoundingClientRect().height) : nextInset;
4770
+ const mobileCollapsed = Boolean(
4771
+ stack?.querySelector('[data-chat-composer-mobile-collapsed="true"]'),
4772
+ );
4773
+ if (!mobileCollapsed) composerExpandedHeightRef.current = expandedComposerHeight;
4774
+ const reservedHeight = Math.max(composerExpandedHeightRef.current, expandedComposerHeight);
4775
+ if (composerReservedHeightRef.current !== reservedHeight) {
4776
+ composerReservedHeightRef.current = reservedHeight;
4777
+ setComposerReservedHeight(reservedHeight);
4778
+ }
4779
const mainSurface = composerOverlayElement?.querySelector<HTMLElement>(
4780
'[data-chat-composer-main-surface="true"]',
4781
);
@@ -4784,6 +4809,8 @@ export default function ChatView(props: ChatViewProps) {
4809
useLayoutEffect(() => {
4810
if (!composerOverlayElement) return;
4811
composerTimelineInsetRef.current = 0;
4812
+ composerReservedHeightRef.current = 0;
4813
+ composerExpandedHeightRef.current = 0;
4814
publishComposerOverlayHeightStable(composerOverlayElement.getBoundingClientRect().height);
4815
// oxlint-disable-next-line react/exhaustive-effect-dependencies -- A thread switch must re-measure the overlay for the new timeline.
4816
}, [activeThreadKey, composerOverlayElement, publishComposerOverlayHeightStable]);
@@ -4796,14 +4823,28 @@ export default function ChatView(props: ChatViewProps) {
4823
};
4824
4825
updateHeight();
4799
- return observeResize(composerOverlayElement, updateHeight);
4826
+ // The hero overlay fills the pane, so the composer's own growth only shows on its stack.
4827
+ const stack = isDraftHeroState
4828
+ ? composerOverlayElement.querySelector<HTMLElement>('[data-chat-composer-stack="true"]')
4829
+ : null;
4830
+ return observeResize(
4831
+ stack ? [composerOverlayElement, stack] : composerOverlayElement,
4832
+ updateHeight,
4833
+ );
4834
+ }, [
4835
+ composerOverlayElement,
4836
+ isDraftHeroState,
4837
+ publishComposerOverlayHeightStable,
4838
// oxlint-disable-next-line react/exhaustive-effect-dependencies -- The scroll-to-bottom button changes the overlay's height without resizing the observed node first.
4801
- }, [composerOverlayElement, publishComposerOverlayHeightStable, showScrollToBottom]);
4839
+ showScrollToBottom,
4840
+ ]);
4841
useLayoutEffect(() => {
4842
if (composerMountedRef.current === composerMounted) return;
4843
composerMountedRef.current = composerMounted;
4844
if (!composerOverlayElement) return;
4845
composerTimelineInsetRef.current = 0;
4846
+ composerReservedHeightRef.current = 0;
4847
+ composerExpandedHeightRef.current = 0;
4848
publishComposerOverlayHeightStable(composerOverlayElement.getBoundingClientRect().height);
4849
}, [composerMounted, composerOverlayElement, publishComposerOverlayHeightStable]);
4850
const openPanelPullRequestUrl = useOpenPanelPullRequestUrl(activeThreadRef);
@@ -7980,6 +8021,7 @@ export default function ChatView(props: ChatViewProps) {
8021
rightPanelMaximized ? "w-0 flex-none" : "flex-1",
8022
)}
8023
data-chat-column-maximized-away={rightPanelMaximized ? "true" : "false"}
8024
+ data-chat-column
8025
>
8026
<header
8027
ref={threadPanelPopoverAnchorRef}
@@ -8197,6 +8239,7 @@ export default function ChatView(props: ChatViewProps) {
8239
onManualNavigation={cancelTimelineLiveFollowForUserNavigationStable}
8240
cancelPositionRestoreRef={cancelPositionRestoreRef}
8241
hideEmptyPlaceholder={isDraftHeroState || threadDetailLoading}
8242
+ emptyPlaceholderInset={composerReservedHeight}
8243
topFadeEnabled={!hasTimelineTopBanner}
8244
{...(paintOnlyDisplayedTimeline || threadHistoryControls === undefined
8245
? {}
@@ -8650,6 +8693,7 @@ export default function ChatView(props: ChatViewProps) {
8693
threadRef={mountedThreadRef}
8694
threadId={mountedThreadRef.threadId}
8695
active={mountedThreadKey === activeThreadKey}
8696
+ composerHeight={mountedThreadKey === activeThreadKey ? composerReservedHeight : 0}
8697
launchContext={
8698
mountedThreadKey === activeThreadKey ? (activeTerminalLaunchContext ?? null) : null
8699
}
apps/web/src/components/PersistentThreadTerminals.tsx
+3
@@ -81,6 +81,7 @@ interface PersistentThreadTerminalDrawerProps {
81
threadRef: { environmentId: EnvironmentId; threadId: ThreadId };
82
threadId: ThreadId;
83
active: boolean;
84
+ composerHeight: number;
85
launchContext: PersistentTerminalLaunchContext | null;
86
focusRequestId: number;
87
splitShortcutLabel: string | undefined;
@@ -95,6 +96,7 @@ export const PersistentThreadTerminalDrawer = memo(function PersistentThreadTerm
96
threadRef,
97
threadId,
98
active,
99
+ composerHeight,
100
launchContext,
101
focusRequestId,
102
splitShortcutLabel,
@@ -268,6 +270,7 @@ export const PersistentThreadTerminalDrawer = memo(function PersistentThreadTerm
270
runtimeEnv={runtimeEnv}
271
visible={visible}
272
height={terminalUiState.terminalHeight}
273
+ composerHeight={composerHeight}
274
// Known-session order is MRU and changes on focus; persisted store order keeps sidebar labels stable.
275
terminalIds={canOperateTerminal ? terminalUiState.terminalIds : serverOrderedTerminalIds}
276
activeTerminalId={terminalUiState.activeTerminalId}
apps/web/src/components/ThreadTerminalDrawer.test.ts
+36
@@ -8,6 +8,8 @@ import {
8
} from "@t3tools/client-runtime/state/terminal";
9
10
import {
11
+ clampDrawerHeight,
12
+ resolveTerminalDrawerMaxHeight,
13
shouldClearTerminalSelectionAction,
14
shouldHandleTerminalExit,
15
terminalContextMenuItems,
@@ -17,6 +19,40 @@ import {
19
terminalThemeFromApp,
20
} from "./ThreadTerminalDrawer";
21
22
+describe("terminal drawer height", () => {
23
+ it("shrinks to fit beside the header and composer while the phone keyboard is open, then restores the preferred height", () => {
24
+ const controls = { headerHeight: 52, composerHeight: 108 };
25
+ const keyboardOpenMax = resolveTerminalDrawerMaxHeight({
26
+ ...controls,
27
+ viewportHeight: 400,
28
+ chatColumnHeight: 360,
29
+ });
30
+ const keyboardClosedMax = resolveTerminalDrawerMaxHeight({
31
+ ...controls,
32
+ viewportHeight: 800,
33
+ chatColumnHeight: 760,
34
+ });
35
+
36
+ // 360 - 52 - 108 leaves 200px, so the drawer stops short of its 280px preference.
37
+ expect(clampDrawerHeight(280, keyboardOpenMax)).toBe(200);
38
+ expect(clampDrawerHeight(280, keyboardClosedMax)).toBe(280);
39
+ });
40
+
41
+ it("keeps the window cap for panel terminals and collapses to zero when the controls fill the column", () => {
42
+ expect(clampDrawerHeight(900, resolveTerminalDrawerMaxHeight({ viewportHeight: 800 }))).toBe(
43
+ 600,
44
+ );
45
+
46
+ const crowdedMax = resolveTerminalDrawerMaxHeight({
47
+ viewportHeight: 200,
48
+ chatColumnHeight: 160,
49
+ headerHeight: 52,
50
+ composerHeight: 120,
51
+ });
52
+ expect(clampDrawerHeight(280, crowdedMax)).toBe(0);
53
+ });
54
+});
55
+
56
describe("terminal selection menus", () => {
57
it("omits Add to chat when the terminal has no chat target", () => {
58
expect(terminalSelectionMenuItems().map(({ id }) => id)).toEqual(["add-to-chat", "copy"]);
apps/web/src/components/ThreadTerminalDrawer.tsx
+85
-25
@@ -88,6 +88,7 @@ import { useEnvironmentScope } from "../state/session";
88
import { openTerminalLinkInPreview } from "./preview/openTerminalLinkInPreview";
89
import { useAtomCommand } from "../state/use-atom-command";
90
import { preventTerminalCloseShortcut } from "../lib/terminalCloseShortcut";
91
+import { observeResize } from "../lib/observeResize";
92
import {
93
resolveTerminalFontPreference,
94
resolveTerminalFontSizePreference,
@@ -97,16 +98,46 @@ import {
98
const MIN_DRAWER_HEIGHT = 180;
99
const MAX_DRAWER_HEIGHT_RATIO = 0.75;
100
100
-function maxDrawerHeight(): number {
101
- if (typeof window === "undefined") return DEFAULT_THREAD_TERMINAL_HEIGHT;
102
- return Math.max(MIN_DRAWER_HEIGHT, Math.floor(window.innerHeight * MAX_DRAWER_HEIGHT_RATIO));
101
+interface DrawerLayout {
102
+ viewportHeight: number;
103
+ chatColumnHeight?: number;
104
+ headerHeight?: number;
105
+ composerHeight?: number;
106
}
107
105
-function clampDrawerHeight(height: number, maxHeight = maxDrawerHeight()): number {
108
+export function resolveTerminalDrawerMaxHeight(input: DrawerLayout): number {
109
+ const windowCap = Math.max(
110
+ MIN_DRAWER_HEIGHT,
111
+ Math.floor(input.viewportHeight * MAX_DRAWER_HEIGHT_RATIO),
112
+ );
113
+ if (input.chatColumnHeight === undefined) return windowCap;
114
+ // The composer overlays the timeline, so flex layout cannot reserve its
115
+ // height; without this cap a tall drawer pushes it into the header.
116
+ return Math.min(
117
+ windowCap,
118
+ Math.max(0, input.chatColumnHeight - (input.headerHeight ?? 0) - (input.composerHeight ?? 0)),
119
+ );
120
+}
121
+
122
+export function clampDrawerHeight(height: number, maxHeight: number): number {
123
const safeHeight = Number.isFinite(height) ? height : DEFAULT_THREAD_TERMINAL_HEIGHT;
124
return Math.min(Math.max(Math.round(safeHeight), MIN_DRAWER_HEIGHT), maxHeight);
125
}
126
127
+function chatColumnOf(drawer: HTMLElement | null): HTMLElement | null {
128
+ return drawer?.closest<HTMLElement>("[data-chat-column]") ?? null;
129
+}
130
+
131
+function readDrawerLayout(column: HTMLElement | null): Omit<DrawerLayout, "composerHeight"> {
132
+ const viewportHeight = typeof window === "undefined" ? 0 : window.innerHeight;
133
+ if (!column) return { viewportHeight };
134
+ return {
135
+ viewportHeight,
136
+ chatColumnHeight: column.clientHeight,
137
+ headerHeight: column.querySelector<HTMLElement>("[data-chat-header]")?.offsetHeight ?? 0,
138
+ };
139
+}
140
+
141
function writeSystemMessage(terminal: GhosttyTerminalSurface, message: string): void {
142
terminal.write(`\r\n[terminal] ${message}\r\n`);
143
}
@@ -1123,6 +1154,8 @@ interface ThreadTerminalDrawerProps {
1154
runtimeEnv?: Record<string, string>;
1155
visible?: boolean;
1156
height: number;
1157
+ /** Space the chat column keeps for the composer overlay; only read in drawer mode. */
1158
+ composerHeight?: number;
1159
terminalIds: string[];
1160
activeTerminalId: string;
1161
terminalGroups: ThreadTerminalGroup[];
@@ -1389,6 +1422,7 @@ export default function ThreadTerminalDrawer({
1422
runtimeEnv,
1423
visible = true,
1424
height,
1425
+ composerHeight = 0,
1426
terminalIds,
1427
activeTerminalId,
1428
terminalGroups,
@@ -1417,14 +1451,16 @@ export default function ThreadTerminalDrawer({
1451
Schema.Boolean,
1452
);
1453
const controlledDrawerHeight = height;
1420
- const [windowMaxDrawerHeight, setWindowMaxDrawerHeight] = useState(maxDrawerHeight);
1454
+ const drawerRef = useRef<HTMLElement | null>(null);
1455
+ const [drawerLayout, setDrawerLayout] = useState(() => readDrawerLayout(null));
1456
+ const maxDrawerHeight = resolveTerminalDrawerMaxHeight({ ...drawerLayout, composerHeight });
1457
const [drawerHeightState, setDrawerHeightState] = useState(() => ({
1458
threadId,
1459
height: controlledDrawerHeight,
1460
}));
1461
const preferredDrawerHeight =
1462
drawerHeightState.threadId === threadId ? drawerHeightState.height : controlledDrawerHeight;
1427
- const drawerHeight = clampDrawerHeight(preferredDrawerHeight, windowMaxDrawerHeight);
1463
+ const drawerHeight = clampDrawerHeight(preferredDrawerHeight, maxDrawerHeight);
1464
const setDrawerHeight = (update: SetStateAction<number>) => {
1465
setDrawerHeightState((current) => {
1466
const currentHeight = current.threadId === threadId ? current.height : controlledDrawerHeight;
@@ -1435,12 +1471,6 @@ export default function ThreadTerminalDrawer({
1471
});
1472
};
1473
const [resizeEpoch, setResizeEpoch] = useState(0);
1438
- const [shownVisible, setShownVisible] = useState(visible);
1439
- if (shownVisible !== visible) {
1440
- setShownVisible(visible);
1441
- // The window may have resized while the drawer was hidden and not listening.
1442
- if (visible) setWindowMaxDrawerHeight(maxDrawerHeight());
1443
- }
1474
const drawerHeightRef = useRef(drawerHeight);
1475
const lastSyncedHeightRef = useRef({ threadId, height: controlledDrawerHeight });
1476
const resizeStateRef = useRef<{
@@ -1658,6 +1688,7 @@ export default function ThreadTerminalDrawer({
1688
event.preventDefault();
1689
const clampedHeight = clampDrawerHeight(
1690
resizeState.startHeight + (resizeState.startY - event.clientY),
1691
+ maxDrawerHeight,
1692
);
1693
if (clampedHeight === drawerHeightRef.current) {
1694
return;
@@ -1675,11 +1706,11 @@ export default function ThreadTerminalDrawer({
1706
event.currentTarget.releasePointerCapture(event.pointerId);
1707
}
1708
// A drag that ends where it started keeps the stored preference, which may
1678
- // be taller than the window-capped height the drag started from.
1709
+ // be taller than the capped height the drag started from.
1710
if (!didResizeDuringDragRef.current || drawerHeightRef.current === resizeState.startHeight) {
1711
// React skips the write when the rendered height did not change, so put
1681
- // back the preference as the current window caps it.
1682
- const renderedHeight = clampDrawerHeight(preferredDrawerHeight);
1712
+ // back the preference as the current layout caps it.
1713
+ const renderedHeight = clampDrawerHeight(preferredDrawerHeight, maxDrawerHeight);
1714
drawerHeightRef.current = renderedHeight;
1715
resizeState.drawer?.style.setProperty("height", `${renderedHeight}px`);
1716
return;
@@ -1689,26 +1720,53 @@ export default function ThreadTerminalDrawer({
1720
setResizeEpoch((value) => value + 1);
1721
};
1722
1692
- useEffect(() => {
1693
- if (!visible) {
1694
- return;
1695
- }
1696
-
1697
- const onWindowResize = () => {
1723
+ const drawerLayoutRef = useRef(drawerLayout);
1724
+ const updateDrawerLayout = useEffectEvent(
1725
+ (column: HTMLElement | null, source: "window" | "column") => {
1726
+ const layout = readDrawerLayout(column);
1727
+ const previous = drawerLayoutRef.current;
1728
+ const heightBudgetChanged =
1729
+ layout.viewportHeight !== previous.viewportHeight ||
1730
+ layout.chatColumnHeight !== previous.chatColumnHeight ||
1731
+ layout.headerHeight !== previous.headerHeight;
1732
+ // The column also reports width-only changes, such as every frame of a
1733
+ // right panel drag; the surface refits itself for those.
1734
+ if (!heightBudgetChanged && source === "column") return;
1735
+ drawerLayoutRef.current = layout;
1736
const resizeState = resizeStateRef.current;
1699
- const liveHeight = clampDrawerHeight(drawerHeightRef.current);
1737
+ const liveHeight = clampDrawerHeight(
1738
+ drawerHeightRef.current,
1739
+ resolveTerminalDrawerMaxHeight({ ...layout, composerHeight }),
1740
+ );
1741
if (resizeState && liveHeight !== drawerHeightRef.current) {
1742
drawerHeightRef.current = liveHeight;
1743
resizeState.drawer?.style.setProperty("height", `${liveHeight}px`);
1744
}
1704
- setWindowMaxDrawerHeight(maxDrawerHeight());
1745
+ if (heightBudgetChanged) setDrawerLayout(layout);
1746
setResizeEpoch((value) => value + 1);
1706
- };
1747
+ },
1748
+ );
1749
+ useLayoutEffect(() => {
1750
+ if (!visible) {
1751
+ return;
1752
+ }
1753
+ // The column and window may have resized while the drawer was hidden and
1754
+ // not listening, so measure before the first visible paint.
1755
+ const column = isPanel ? null : chatColumnOf(drawerRef.current);
1756
+ const onWindowResize = () => updateDrawerLayout(column, "window");
1757
+ onWindowResize();
1758
+ const header = column?.querySelector<HTMLElement>("[data-chat-header]");
1759
+ const stopObserving = column
1760
+ ? observeResize(header ? [column, header] : column, () =>
1761
+ updateDrawerLayout(column, "column"),
1762
+ )
1763
+ : undefined;
1764
window.addEventListener("resize", onWindowResize);
1765
return () => {
1766
+ stopObserving?.();
1767
window.removeEventListener("resize", onWindowResize);
1768
};
1711
- }, [visible]);
1769
+ }, [isPanel, visible]);
1770
1771
const syncPreferredHeight = useEffectEvent(() => syncHeight(preferredDrawerHeight));
1772
useEffect(() => () => syncPreferredHeight(), []);
@@ -1716,6 +1774,7 @@ export default function ThreadTerminalDrawer({
1774
if (normalizedTerminalIds.length === 0) {
1775
return (
1776
<aside
1777
+ ref={drawerRef}
1778
data-thread-terminal-drawer
1779
data-terminal-owner={isPanel ? "right-panel" : "drawer"}
1780
className={cn(
@@ -1751,6 +1810,7 @@ export default function ThreadTerminalDrawer({
1810
1811
return (
1812
<aside
1813
+ ref={drawerRef}
1814
data-thread-terminal-drawer
1815
data-terminal-owner={isPanel ? "right-panel" : "drawer"}
1816
className={cn(
apps/web/src/components/chat/MessagesTimeline.browser.test.tsx
+1
@@ -80,6 +80,7 @@ function baseProps(): Omit<TimelineProps, "timelineEntries"> {
80
onAnchorReady: () => {},
81
onAnchorSizeChanged: () => {},
82
contentInsetEndAdjustment: 0,
83
+ emptyPlaceholderInset: 0,
84
liveFollowEnabled: true,
85
onIsAtEndChange: () => {},
86
onManualNavigation: () => {},
apps/web/src/components/chat/MessagesTimeline.tsx
+4
-1
@@ -516,6 +516,8 @@ interface MessagesTimelineProps {
516
findOpen?: boolean;
517
cancelPositionRestoreRef?: React.RefObject<(() => void) | null> | undefined;
518
hideEmptyPlaceholder?: boolean;
519
+ /** Composer space to center the empty state against; held steady through collapse. */
520
+ emptyPlaceholderInset: number;
521
topFadeEnabled?: boolean;
522
historyControls?: MessagesTimelineHistoryControls | undefined;
523
loadEarlier?: CitationHistoryPage | null;
@@ -607,6 +609,7 @@ const ConversationTimeline = memo(function ConversationTimeline({
609
onManualNavigation,
610
cancelPositionRestoreRef,
611
hideEmptyPlaceholder = false,
612
+ emptyPlaceholderInset,
613
topFadeEnabled = false,
614
historyControls,
615
loadEarlier = null,
@@ -1454,7 +1457,7 @@ const ConversationTimeline = memo(function ConversationTimeline({
1457
return (
1458
<div
1459
className="flex h-full items-center justify-center ps-(--chat-lane-inset-start) pe-(--chat-lane-inset-end)"
1457
- style={{ paddingBottom: contentInsetEndAdjustment }}
1460
+ style={{ paddingBottom: emptyPlaceholderInset }}
1461
>
1462
<p className="text-sm text-muted-foreground/30">
1463
Send a message to start the conversation.