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, 08:15 UTC
fix(web): make Changes and PR Code file lists resizable (#28244)
Co-authored-by: Lukas Tomondy <lukas.tomondy@moonpyre.com>
Lukas committed
Nov 1, 2026 at 03:48 UTC
9ff0fac0f4893179ef5588577007a95043a7d93e
6 files changed
+194
-21
apps/web/src/components/DiffPanel.tsx
+8
-2
@@ -67,6 +67,7 @@ import { DiffPanelLoadingState, DiffPanelShell, type DiffPanelMode } from "./Dif
67
import { DiffStatLabel } from "./chat/DiffStatLabel";
68
import { AnnotatableCodeView } from "./diffs/AnnotatableCodeView";
69
import { DiffFileTree } from "./diffs/DiffFileTree";
70
+import { FileExplorerPane } from "./files/FileExplorerPane";
71
import { diffFileTreeEntries } from "./diffs/diffFileTree.logic";
72
import { Button } from "./ui/button";
73
import { MorphIcon } from "~/components/MorphIcon";
@@ -1451,7 +1452,12 @@ export default function DiffPanel({
1452
/>
1453
</div>
1454
{fileTreeOpen ? (
1454
- <aside className="flex w-[min(16rem,40%)] min-w-40 shrink-0 border-l border-border/60">
1455
+ <FileExplorerPane
1456
+ resizable
1457
+ storageKey="t3code:diff-file-tree-width"
1458
+ defaultWidthFraction={0.4}
1459
+ resizeLabel="Resize Changes files"
1460
+ >
1461
<DiffFileTree
1462
ariaLabel={`${reviewSectionTitle} files`}
1463
entries={fileTreeEntries}
@@ -1459,7 +1465,7 @@ export default function DiffPanel({
1465
revealRequestId={selectedFileRevealRequestId}
1466
onSelectFile={revealDiffFile}
1467
/>
1462
- </aside>
1468
+ </FileExplorerPane>
1469
) : null}
1470
</div>
1471
) : (
apps/web/src/components/files/FileExplorerPane.browser.test.tsx
new
+45
@@ -0,0 +1,45 @@
1
+import { describe, expect, it } from "vite-plus/test";
2
+
3
+import { render } from "../../../test/render";
4
+import { FileExplorerPane } from "./FileExplorerPane";
5
+
6
+const STORAGE_KEY = "test:file-explorer-default";
7
+
8
+describe("FileExplorerPane", () => {
9
+ it.each([
10
+ { view: "Changes", defaultWidth: 256, defaultWidthFraction: 0.4, minWidth: 160, expected: 168 },
11
+ { view: "PR Code", defaultWidth: 320, defaultWidthFraction: 0.4, minWidth: 192, expected: 192 },
12
+ {
13
+ view: "Files",
14
+ defaultWidth: 256,
15
+ minWidth: 160,
16
+ expected: 164,
17
+ },
18
+ ])(
19
+ "preserves the $view initial width in a 420px row",
20
+ async ({ expected, view: _, ...sizing }) => {
21
+ const previous = localStorage.getItem(STORAGE_KEY);
22
+ localStorage.removeItem(STORAGE_KEY);
23
+ try {
24
+ // This layout has no navigation or links.
25
+ await using screen = await render(
26
+ <div style={{ display: "flex", width: 420 }}>
27
+ <FileExplorerPane resizable storageKey={STORAGE_KEY} {...sizing}>
28
+ File tree
29
+ </FileExplorerPane>
30
+ </div>,
31
+ { router: false },
32
+ );
33
+ await expect
34
+ .element(screen.getByRole("separator"))
35
+ .toHaveAttribute("aria-valuenow", String(expected));
36
+ expect(screen.container.querySelector("aside")!.getBoundingClientRect().width).toBe(
37
+ expected,
38
+ );
39
+ } finally {
40
+ if (previous === null) localStorage.removeItem(STORAGE_KEY);
41
+ else localStorage.setItem(STORAGE_KEY, previous);
42
+ }
43
+ },
44
+ );
45
+});
apps/web/src/components/files/FileExplorerPane.tsx
+33
-9
@@ -9,18 +9,33 @@ const MIN_WIDTH = 160;
9
const MAX_WIDTH = 560;
10
const FILE_CONTENT_MIN_WIDTH = 256;
11
12
+/** A persisted, resizable file-tree column; fills the row when resizing is disabled.
13
+ * Callers can retain a responsive initial width via defaultWidthFraction (a fraction of the row),
14
+ * and use a separate saved width, minimum and resize label. A chosen width overrides the default.
15
+ */
16
export function FileExplorerPane({
17
resizable,
18
children,
19
+ storageKey = "t3code.fileExplorerWidth",
20
+ defaultWidth = 256,
21
+ defaultWidthFraction,
22
+ minWidth = MIN_WIDTH,
23
+ resizeLabel = "Resize file explorer",
24
}: {
25
resizable: boolean;
26
children: ReactNode;
27
+ storageKey?: string;
28
+ defaultWidth?: number;
29
+ defaultWidthFraction?: number;
30
+ minWidth?: number;
31
+ resizeLabel?: string;
32
}) {
33
const [maxWidth, setMaxWidth] = useState(MAX_WIDTH);
34
+ const [responsiveDefaultWidth, setResponsiveDefaultWidth] = useState(defaultWidth);
35
const { width, setWidth, handlers } = useResizableWidth({
21
- storageKey: "t3code.fileExplorerWidth",
22
- defaultWidth: 256,
23
- minWidth: MIN_WIDTH,
36
+ storageKey,
37
+ defaultWidth: responsiveDefaultWidth,
38
+ minWidth,
39
maxWidth,
40
edge: "left",
41
});
@@ -30,10 +45,19 @@ export function FileExplorerPane({
45
ref={(host) => {
46
const row = host?.parentElement;
47
if (!row || !resizable) return;
33
- const measure = () =>
34
- setMaxWidth(
35
- Math.max(MIN_WIDTH, Math.min(MAX_WIDTH, row.clientWidth - FILE_CONTENT_MIN_WIDTH)),
48
+ const measure = () => {
49
+ const initialWidth = Math.max(
50
+ minWidth,
51
+ Math.min(defaultWidth, row.clientWidth * (defaultWidthFraction ?? 1)),
52
);
53
+ // A responsive default must not shrink to make room for the content reserve.
54
+ const availableWidth = Math.max(
55
+ row.clientWidth - FILE_CONTENT_MIN_WIDTH,
56
+ defaultWidthFraction === undefined ? minWidth : initialWidth,
57
+ );
58
+ setMaxWidth(Math.max(minWidth, Math.min(MAX_WIDTH, availableWidth)));
59
+ setResponsiveDefaultWidth(initialWidth);
60
+ };
61
measure();
62
return observeResize(row, measure);
63
}}
@@ -54,10 +78,10 @@ export function FileExplorerPane({
78
{resizable ? (
79
<RightPanelResizeHandle
80
handlers={handlers}
57
- label="Resize file explorer"
81
+ label={resizeLabel}
82
tabIndex={0}
83
aria-valuenow={width}
60
- aria-valuemin={MIN_WIDTH}
84
+ aria-valuemin={minWidth}
85
aria-valuemax={maxWidth}
86
onKeyDown={(event) => {
87
if (event.altKey || event.ctrlKey || event.metaKey) return;
@@ -70,7 +94,7 @@ export function FileExplorerPane({
94
nextWidth = width - 16;
95
break;
96
case "Home":
73
- nextWidth = MIN_WIDTH;
97
+ nextWidth = minWidth;
98
break;
99
case "End":
100
nextWidth = maxWidth;
apps/web/src/components/pullRequest/PullRequestCodeTab.tsx
+10
-2
@@ -81,6 +81,7 @@ import { DiffPanelLoadingState } from "../DiffPanelShell";
81
import { useDiffWorkerPool } from "../DiffWorkerPoolProvider";
82
import { DiffCommentAnnotation } from "../diffs/DiffCommentAnnotation";
83
import { DiffFileTree } from "../diffs/DiffFileTree";
84
+import { FileExplorerPane } from "../files/FileExplorerPane";
85
import { useCodeViewFileReveal } from "../diffs/useCodeViewFileReveal";
86
import { useHideTestFiles } from "../diffs/useHideTestFiles";
87
import { diffFileTreeEntries, orderDiffFilesLikeTree } from "../diffs/diffFileTree.logic";
@@ -1515,7 +1516,14 @@ function PullRequestCodeTab({
1516
</FileViewedToggleContext>
1517
</div>
1518
{fileTreeOpen ? (
1518
- <aside className="flex w-[min(20rem,40%)] min-w-48 shrink-0 border-l border-border/60">
1519
+ <FileExplorerPane
1520
+ resizable
1521
+ storageKey="t3code:diff-file-tree-width"
1522
+ defaultWidth={320}
1523
+ defaultWidthFraction={0.4}
1524
+ minWidth={192}
1525
+ resizeLabel="Resize PR Code files"
1526
+ >
1527
<DiffFileTree
1528
ariaLabel={`${capitalizeTerm(term)} #${detail.number} files`}
1529
entries={fileTreeEntries}
@@ -1541,7 +1549,7 @@ function PullRequestCodeTab({
1549
)
1550
}
1551
/>
1544
- </aside>
1552
+ </FileExplorerPane>
1553
) : null}
1554
</div>
1555
{unstructured}
apps/web/src/hooks/useResizableWidth.browser.test.tsx
new
+85
@@ -0,0 +1,85 @@
1
+import { describe, expect, it, vi } from "vite-plus/test";
2
+
3
+import { act, render } from "../../test/render";
4
+import { RESIZABLE_WIDTH_PROPERTY, useResizableWidth } from "./useResizableWidth";
5
+
6
+const STORAGE_KEY = "test:responsive-panel-width";
7
+
8
+function Panel({ defaultWidth }: { defaultWidth: number }) {
9
+ const { width, setWidth, handlers } = useResizableWidth({
10
+ storageKey: STORAGE_KEY,
11
+ defaultWidth,
12
+ minWidth: 160,
13
+ maxWidth: 560,
14
+ edge: "left",
15
+ });
16
+ return (
17
+ <>
18
+ <button onClick={() => setWidth(350)}>{width}</button>
19
+ <div role="separator" style={{ width: 8, height: 40 }} {...handlers} />
20
+ </>
21
+ );
22
+}
23
+
24
+describe("useResizableWidth", () => {
25
+ it("follows a responsive default until the user saves a width", async () => {
26
+ const previous = localStorage.getItem(STORAGE_KEY);
27
+ localStorage.removeItem(STORAGE_KEY);
28
+ try {
29
+ // This hook only needs browser storage and React; no navigation is involved.
30
+ await using screen = await render(<Panel defaultWidth={320} />, { router: false });
31
+ expect(screen.container.textContent).toBe("320");
32
+ await screen.rerender(<Panel defaultWidth={200} />);
33
+ expect(screen.container.textContent).toBe("200");
34
+
35
+ await act(() => screen.container.querySelector("button")!.click());
36
+ await screen.rerender(<Panel defaultWidth={180} />);
37
+ expect(screen.container.textContent).toBe("350");
38
+
39
+ await screen.unmount();
40
+ await using restored = await render(<Panel defaultWidth={200} />, { router: false });
41
+ expect(restored.container.textContent).toBe("350");
42
+ } finally {
43
+ if (previous === null) localStorage.removeItem(STORAGE_KEY);
44
+ else localStorage.setItem(STORAGE_KEY, previous);
45
+ }
46
+ });
47
+
48
+ it("keeps the default responsive after a stationary click and persists an actual drag", async () => {
49
+ const previous = localStorage.getItem(STORAGE_KEY);
50
+ localStorage.removeItem(STORAGE_KEY);
51
+ try {
52
+ // This hook only needs browser storage and React; no navigation is involved.
53
+ await using screen = await render(<Panel defaultWidth={240} />, { router: false });
54
+ await screen.getByRole("separator").click();
55
+ expect(localStorage.getItem(STORAGE_KEY)).toBeNull();
56
+ await screen.rerender(<Panel defaultWidth={256} />);
57
+ expect(screen.container.textContent).toBe("256");
58
+
59
+ const handle = screen.container.querySelector<HTMLElement>('[role="separator"]')!;
60
+ // Synthetic drag events have no active browser pointer to capture.
61
+ using _capture = vi.spyOn(handle, "setPointerCapture").mockImplementation(() => {});
62
+ const pointer = { bubbles: true, pointerId: 1, button: 0 };
63
+ await act(() => {
64
+ handle.dispatchEvent(new PointerEvent("pointerdown", { ...pointer, clientX: 500 }));
65
+ });
66
+ await screen.rerender(<Panel defaultWidth={280} />);
67
+ await act(() => {
68
+ handle.dispatchEvent(new PointerEvent("pointerup", { ...pointer, clientX: 500 }));
69
+ });
70
+ expect(localStorage.getItem(STORAGE_KEY)).toBeNull();
71
+ expect(screen.container.style.getPropertyValue(RESIZABLE_WIDTH_PROPERTY)).toBe("280px");
72
+
73
+ await act(() => {
74
+ handle.dispatchEvent(new PointerEvent("pointerdown", { ...pointer, clientX: 500 }));
75
+ handle.dispatchEvent(new PointerEvent("pointerup", { ...pointer, clientX: 450 }));
76
+ });
77
+ expect(localStorage.getItem(STORAGE_KEY)).toBe("330");
78
+ await screen.rerender(<Panel defaultWidth={200} />);
79
+ expect(screen.container.textContent).toBe("330");
80
+ } finally {
81
+ if (previous === null) localStorage.removeItem(STORAGE_KEY);
82
+ else localStorage.setItem(STORAGE_KEY, previous);
83
+ }
84
+ });
85
+});
apps/web/src/hooks/useResizableWidth.ts
+13
-8
@@ -3,6 +3,7 @@ import { type PointerEvent as ReactPointerEvent, useLayoutEffect, useState } fro
3
4
import { getLocalStorageItem, setLocalStorageItem } from "./useLocalStorage";
5
import { useResizeDrag } from "./useResizeDrag";
6
+import { useStableCallback } from "./useStableCallback";
7
8
const WidthSchema = Schema.Finite;
9
@@ -26,7 +27,7 @@ export interface ResizableWidthHandlers {
27
readonly onLostPointerCapture: (event: ReactPointerEvent<HTMLElement>) => void;
28
}
29
29
-/** Persist on drag end to avoid a storage write on every animation frame. */
30
+/** Uses the current default until a width is chosen; persists on drag end, not every frame. */
31
export function useResizableWidth(options: UseResizableWidthOptions): {
32
readonly width: number;
33
readonly setWidth: (width: number) => void;
@@ -39,14 +40,14 @@ export function useResizableWidth(options: UseResizableWidthOptions): {
40
return Math.max(minWidth, Math.min(maxWidth, value));
41
};
42
42
- const readWidth = () => {
43
- if (typeof window === "undefined") return defaultWidth;
43
+ const readWidth = (): number | null => {
44
+ if (typeof window === "undefined") return null;
45
try {
46
const stored = getLocalStorageItem(storageKey, WidthSchema);
46
- return clamp(stored ?? defaultWidth);
47
+ return stored === null ? null : clamp(stored);
48
} catch (error) {
49
console.error("Could not read persisted panel width.", error);
49
- return defaultWidth;
50
+ return null;
51
}
52
};
53
const [widthState, setWidthState] = useState(() => ({ storageKey, width: readWidth() }));
@@ -54,7 +55,10 @@ export function useResizableWidth(options: UseResizableWidthOptions): {
55
setWidthState({ storageKey, width: readWidth() });
56
}
57
57
- const clampedWidth = clamp(widthState.width);
58
+ const clampedWidth = clamp(widthState.width ?? defaultWidth);
59
+ const restoreWidth = useStableCallback((host: HTMLElement | null) => {
60
+ host?.style.setProperty(RESIZABLE_WIDTH_PROPERTY, `${clampedWidth}px`);
61
+ });
62
63
const commitWidth = (nextStorageKey: string, nextWidth: number) => {
64
// Resizing remains usable for this session when browser storage is unavailable.
@@ -82,8 +86,9 @@ export function useResizableWidth(options: UseResizableWidthOptions): {
86
host?.style.setProperty(RESIZABLE_WIDTH_PROPERTY, `${nextWidth}px`);
87
return nextWidth;
88
},
85
- finish(finalWidth) {
86
- commitWidth(startStorageKey, finalWidth);
89
+ finish(finalWidth, moved) {
90
+ if (moved) commitWidth(startStorageKey, finalWidth);
91
+ else restoreWidth(host);
92
},
93
cleanup(committed) {
94
host?.style.removeProperty("transition-property");