@devries-cameron20 / t3code-1 / commits / 1b41060585
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

perf(web): the diff file tree compiles with the React Compiler (#20631)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Julius Marminge committed Oct 16, 2026 at 21:59 UTC 1b41060585be44439a7d00b7168313daeac6b695
1 file changed +25 -23
apps/web/src/components/diffs/DiffFileTree.tsx
+25 -23
@@ -1,8 +1,9 @@
1 import type { GitStatusEntry } from "@pierre/trees";
2 import { FileTree, useFileTree, useFileTreeSelector } from "@pierre/trees/react";
3 import { ChevronsDownUp, ChevronsUpDown } from "lucide";
4 -import { useEffect, useMemo, useRef, useState, type ReactNode } from "react";
4 +import { useEffect, useRef, useState, type ReactNode } from "react";
5
6 +import { useStableCallback } from "~/hooks/useStableCallback";
7 import { useTheme } from "~/hooks/useTheme";
8 import { cn } from "~/lib/utils";
9 import { T3_PIERRE_ICONS } from "~/pierre-icons";
@@ -44,9 +45,9 @@ export function DiffFileTree({
45 className,
46 }: DiffFileTreeProps) {
47 const { resolvedTheme } = useTheme();
47 - const paths = useMemo(() => entries.map((entry) => entry.path), [entries]);
48 - const directoryPaths = useMemo(() => collectDirectoryPaths(paths), [paths]);
49 - const positions = useMemo(() => diffFileTreePositions(paths), [paths]);
48 + const paths = entries.map((entry) => entry.path);
49 + const directoryPaths = collectDirectoryPaths(paths);
50 + const positions = diffFileTreePositions(paths);
51 const [ordering] = useState(() => {
52 let currentPositions: ReadonlyMap<string, number> = new Map();
53 return {
@@ -56,31 +57,27 @@ export function DiffFileTree({
57 },
58 };
59 });
59 - const gitStatus = useMemo<ReadonlyArray<GitStatusEntry>>(
60 - () => entries.map((entry) => ({ path: entry.path, status: entry.status })),
61 - [entries],
62 - );
63 - const filePathsRef = useRef<ReadonlySet<string>>(new Set(paths));
64 - const onSelectFileRef = useRef(onSelectFile);
60 + const gitStatus: ReadonlyArray<GitStatusEntry> = entries.map((entry) => ({
61 + path: entry.path,
62 + status: entry.status,
63 + }));
64 const syncingSelectionRef = useRef(false);
65 const handledRevealRef = useRef<{ path: string; revealRequestId: number } | null>(null);
66 const mountedPathsRef = useRef<ReadonlyArray<string> | null>(null);
67
69 - useEffect(() => {
70 - filePathsRef.current = new Set(paths);
71 - onSelectFileRef.current = onSelectFile;
72 - }, [onSelectFile, paths]);
68 + // The tree model keeps the first selection handler it was given.
69 + const handleSelectionChange = useStableCallback((selectedPaths: ReadonlyArray<string>) => {
70 + if (syncingSelectionRef.current) return;
71 + const path = selectedPaths.at(-1)?.replace(/\/$/, "");
72 + if (path && paths.includes(path)) onSelectFile(path);
73 + });
74
75 const { model } = useFileTree({
76 density: "compact",
77 flattenEmptyDirectories: true,
78 initialExpansion: "open",
79 icons: T3_PIERRE_ICONS,
79 - onSelectionChange: (selectedPaths) => {
80 - if (syncingSelectionRef.current) return;
81 - const path = selectedPaths.at(-1)?.replace(/\/$/, "");
82 - if (path && filePathsRef.current.has(path)) onSelectFileRef.current(path);
83 - },
80 + onSelectionChange: handleSelectionChange,
81 paths: [],
82 search: false,
83 sort: ordering.sort,
@@ -144,8 +141,13 @@ export function DiffFileTree({
141 queueMicrotask(() => {
142 syncingSelectionRef.current = false;
143 });
147 - // `paths` is a dependency so a file that arrives after it was asked for is still revealed.
148 - }, [model, paths, revealRequestId, selectedPath]);
144 + }, [
145 + model,
146 + // oxlint-disable-next-line react/exhaustive-effect-dependencies -- A file that arrives after it was asked for is still revealed.
147 + paths,
148 + revealRequestId,
149 + selectedPath,
150 + ]);
151
152 return (
153 <div className={cn("flex min-h-0 flex-1 flex-col bg-background", className)}>
@@ -202,13 +204,13 @@ export function DiffFileTree({
204 // Read selection before the row handles the click so new selections reveal only once.
205 const selected = model.getSelectedPaths();
206 const path = selected.length === 1 ? selected[0] : undefined;
205 - if (!path || !filePathsRef.current.has(path)) return;
207 + if (!path || !paths.includes(path)) return;
208 const clickedSelectedRow = event.nativeEvent
209 .composedPath()
210 .some(
211 (node) => node instanceof HTMLElement && node.getAttribute("data-item-path") === path,
212 );
211 - if (clickedSelectedRow) onSelectFileRef.current(path);
213 + if (clickedSelectedRow) onSelectFile(path);
214 }}
215 className="min-h-0 flex-1 overflow-hidden"
216 style={pierreTreeStyle(resolvedTheme)}