@devries-cameron20 / t3code Mirror · read-only / commits / a77cbf0d5e
Fork 0

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 23, 08:00 UTC

perf(web): the file browser panel compiles with the React Compiler (#20483)

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

Julius Marminge committed Oct 16, 2026 at 18:46 UTC a77cbf0d5ed91bdb067f69e45714ed0346d404a4
2 files changed +127 -104
apps/web/reactCompiledFiles.ts
+1
@@ -58,4 +58,5 @@ export const REACT_COMPILED_FILES = [
58 "apps/web/src/components/usage/UsagePage.tsx",
59 "apps/web/src/components/ProviderUpdateEnvironmentRows.tsx",
60 "apps/web/src/components/files/useDirectoryEntries.ts",
61 + "apps/web/src/components/files/FileBrowserPanel.tsx",
62 ] as const;
apps/web/src/components/files/FileBrowserPanel.tsx
+126 -104
@@ -5,9 +5,12 @@ import type {
5 } from "@pierre/trees";
6 import type { EnvironmentId, ProjectEntry } from "@t3tools/contracts";
7 import { FileTree, useFileTree, useFileTreeSearch, useFileTreeSelector } from "@pierre/trees/react";
8 +import { settlePromise } from "@t3tools/client-runtime/state/runtime";
9 import { serializeComposerFileLink } from "@t3tools/shared/composerTrigger";
10 +import * as AsyncResult from "effect/reactivity/AsyncResult";
11 +import * as Cause from "effect/Cause";
12 import { ChevronsDownUp, ChevronsUpDown } from "lucide";
10 -import { useEffect, useMemo, useRef, useState } from "react";
13 +import { useEffect, useRef, useState, type RefObject } from "react";
14
15 import { Button } from "~/components/ui/button";
16 import { InputGroup, InputGroupInput } from "~/components/ui/input-group";
@@ -16,6 +19,7 @@ import { toastManager } from "~/components/ui/toast";
19 import { Tooltip, TooltipPopup, TooltipTrigger } from "~/components/ui/tooltip";
20 import { useComposerHandleContext } from "~/composerHandleContext";
21 import { writeTextToClipboard } from "~/hooks/useCopyToClipboard";
22 +import { useStableCallback } from "~/hooks/useStableCallback";
23 import { useTheme } from "~/hooks/useTheme";
24 import { useWorkspaceMutationRefresh } from "~/hooks/useWorkspaceMutationRefresh";
25 import { useFileContextMenu, type FileContextMenuAction } from "~/fileContextMenu";
@@ -101,6 +105,47 @@ function FileSearchField(props: {
105 );
106 }
107
108 +// The tree diffs `treePaths` by identity, so these derivations must stay cached
109 +// across the hooks that read them.
110 +function useTreeEntries(
111 + directoryEntries: readonly ProjectEntry[],
112 + searchEntries: readonly ProjectEntry[],
113 + searchPending: boolean,
114 + query: string,
115 +) {
116 + "use memo";
117 + const result = new Map(directoryEntries.map((entry) => [entry.path, entry]));
118 + if (query.trim() && !searchPending) {
119 + for (const entry of searchEntries) {
120 + if (!result.has(entry.path)) result.set(entry.path, entry);
121 + const segments = entry.path.split("/");
122 + for (let index = 1; index < segments.length; index++) {
123 + const path = segments.slice(0, index).join("/");
124 + if (!result.has(path)) result.set(path, { path, kind: "directory" });
125 + }
126 + }
127 + }
128 + const entries = [...result.values()];
129 + const entryKinds: ReadonlyMap<string, ProjectEntry["kind"]> = new Map(
130 + entries.map((entry) => [entry.path, entry.kind] as const),
131 + );
132 + const treePaths = entries.map(treePath);
133 + const directoryPaths = entries.filter((entry) => entry.kind === "directory").map(treePath);
134 + return { entries, entryKinds, treePaths, directoryPaths };
135 +}
136 +
137 +function useDragMentionController(
138 + cwd: string,
139 + hostFolder: boolean,
140 + treeModelRef: RefObject<ReturnType<typeof useFileTree>["model"] | null>,
141 +) {
142 + "use memo";
143 + return createFileTreeDragMentionController({
144 + deselect: (path) => treeModelRef.current?.getItem(path)?.deselect(),
145 + ...(hostFolder ? { mentionPath: (path: string) => joinHostPath(cwd, path) } : {}),
146 + });
147 +}
148 +
149 export default function FileBrowserPanel({
150 environmentId,
151 cwd,
@@ -132,30 +177,13 @@ export default function FileBrowserPanel({
177 { environmentId, cwd: hostFolder ? null : cwd, query: query.slice(0, 256) },
178 200,
179 );
135 - const entries = useMemo(() => {
136 - const result = new Map(directoryEntries.map((entry) => [entry.path, entry]));
137 - if (query.trim() && !pathSearch.isPending) {
138 - for (const entry of pathSearch.entries) {
139 - if (!result.has(entry.path)) result.set(entry.path, entry);
140 - const segments = entry.path.split("/");
141 - for (let index = 1; index < segments.length; index++) {
142 - const path = segments.slice(0, index).join("/");
143 - if (!result.has(path)) result.set(path, { path, kind: "directory" });
144 - }
145 - }
146 - }
147 - return [...result.values()];
148 - }, [directoryEntries, pathSearch.entries, pathSearch.isPending, query]);
149 - const entryKinds = useMemo(
150 - () => new Map(entries.map((entry) => [entry.path, entry.kind] as const)),
151 - [entries],
152 - );
153 - const entryKindsRef = useRef<ReadonlyMap<string, ProjectEntry["kind"]>>(entryKinds);
154 - const treePaths = useMemo(() => entries.map(treePath), [entries]);
155 - const directoryPaths = useMemo(
156 - () => entries.filter((entry) => entry.kind === "directory").map(treePath),
157 - [entries],
180 + const { entries, entryKinds, treePaths, directoryPaths } = useTreeEntries(
181 + directoryEntries,
182 + pathSearch.entries,
183 + pathSearch.isPending,
184 + query,
185 );
186 + const entryKindsRef = useRef(entryKinds);
187 const previousTreePathsRef = useRef<readonly string[] | null>(null);
188 const syncingSelectionRef = useRef(false);
189 const treeSelectionPathRef = useRef<string | null>(null);
@@ -173,100 +201,94 @@ export default function FileBrowserPanel({
201 return () => document.removeEventListener("contextmenu", capturePointer, true);
202 }, []);
203
176 - const showEntryContextMenu = async (
177 - item: TreeContextMenuItem,
178 - context: TreeContextMenuOpenContext,
179 - ) => {
180 - const api = readLocalApi();
181 - if (!api) {
182 - context.close();
183 - return;
184 - }
185 - const relativePath = item.path.replace(/\/$/, "");
186 - const mention = serializeComposerFileLink(panelPath(relativePath));
187 - const pointer = contextMenuPointerRef.current;
188 - const pointerIsFresh = pointer !== null && performance.now() - pointer.at < 1000;
189 - const anchorRect = context.anchorElement.getBoundingClientRect();
190 - const position = pointerIsFresh
191 - ? { x: pointer.x, y: pointer.y }
192 - : { x: anchorRect.left, y: anchorRect.bottom };
193 - const fileTarget = { environmentId, filePath: relativePath, workspaceRoot: cwd };
194 - const fileMenuItems = fileContextMenu.buildItems(fileTarget);
195 - try {
196 - const clicked = await api.contextMenu.show(
197 - [
198 - ...fileMenuItems,
199 - { id: "copy-mention", label: "Copy mention" },
200 - { id: "add-to-chat", label: "Add to chat" },
201 - ],
202 - position,
203 - );
204 - if (clicked === null) return;
205 - // "Open with" submenu selections report the child id ("editor:<id>"),
206 - // which is not present in the top-level item list.
207 - const isFileMenuAction =
208 - fileMenuItems.some((entry) => entry.id === clicked) || clicked.startsWith("editor:");
209 - if (isFileMenuAction) {
210 - await fileContextMenu.activate(clicked as FileContextMenuAction, fileTarget);
204 + const showEntryContextMenu = useStableCallback(
205 + (item: TreeContextMenuItem, context: TreeContextMenuOpenContext) => {
206 + const api = readLocalApi();
207 + if (!api) {
208 + context.close();
209 return;
210 }
213 - if (clicked === "copy-mention") {
214 - try {
215 - await writeTextToClipboard(mention);
216 - toastManager.add({ type: "success", title: "Mention copied", description: relativePath });
217 - } catch (error) {
218 - toastManager.add({
219 - type: "error",
220 - title: "Failed to copy mention",
221 - description: error instanceof Error ? error.message : "An error occurred.",
222 - });
211 + const relativePath = item.path.replace(/\/$/, "");
212 + const mention = serializeComposerFileLink(panelPath(relativePath));
213 + const pointer = contextMenuPointerRef.current;
214 + const pointerIsFresh = pointer !== null && performance.now() - pointer.at < 1000;
215 + const anchorRect = context.anchorElement.getBoundingClientRect();
216 + const position = pointerIsFresh
217 + ? { x: pointer.x, y: pointer.y }
218 + : { x: anchorRect.left, y: anchorRect.bottom };
219 + const fileTarget = { environmentId, filePath: relativePath, workspaceRoot: cwd };
220 + const fileMenuItems = fileContextMenu.buildItems(fileTarget);
221 + void settlePromise(async () => {
222 + const clicked = await api.contextMenu.show(
223 + [
224 + ...fileMenuItems,
225 + { id: "copy-mention", label: "Copy mention" },
226 + { id: "add-to-chat", label: "Add to chat" },
227 + ],
228 + position,
229 + );
230 + if (clicked === null) return;
231 + // "Open with" submenu selections report the child id ("editor:<id>"),
232 + // which is not present in the top-level item list.
233 + const isFileMenuAction =
234 + fileMenuItems.some((entry) => entry.id === clicked) || clicked.startsWith("editor:");
235 + if (isFileMenuAction) {
236 + await fileContextMenu.activate(clicked as FileContextMenuAction, fileTarget);
237 + return;
238 }
224 - return;
225 - }
226 - if (clicked === "add-to-chat") {
227 - const composer = composerRef?.current;
228 - if (!composer) {
229 - toastManager.add({
230 - type: "error",
231 - title: "Unable to add to chat",
232 - description: "Open a chat for this project and try again.",
233 - });
239 + if (clicked === "copy-mention") {
240 + try {
241 + await writeTextToClipboard(mention);
242 + toastManager.add({
243 + type: "success",
244 + title: "Mention copied",
245 + description: relativePath,
246 + });
247 + } catch (error) {
248 + toastManager.add({
249 + type: "error",
250 + title: "Failed to copy mention",
251 + description: error instanceof Error ? error.message : "An error occurred.",
252 + });
253 + }
254 return;
255 }
236 - const inserted = composer.insertTextAtEnd(`${mention} `, { ensureLeadingBoundary: true });
237 - if (!inserted) {
238 - toastManager.add({
239 - type: "error",
240 - title: "Unable to add to chat",
241 - description: "The chat isn't ready to accept input right now.",
242 - });
256 + if (clicked === "add-to-chat") {
257 + const composer = composerRef?.current;
258 + if (!composer) {
259 + toastManager.add({
260 + type: "error",
261 + title: "Unable to add to chat",
262 + description: "Open a chat for this project and try again.",
263 + });
264 + return;
265 + }
266 + const inserted = composer.insertTextAtEnd(`${mention} `, { ensureLeadingBoundary: true });
267 + if (!inserted) {
268 + toastManager.add({
269 + type: "error",
270 + title: "Unable to add to chat",
271 + description: "The chat isn't ready to accept input right now.",
272 + });
273 + }
274 }
244 - }
245 - } finally {
246 - context.close();
247 - }
248 - };
249 - const showEntryContextMenuRef = useRef(showEntryContextMenu);
250 - useEffect(() => {
251 - showEntryContextMenuRef.current = showEntryContextMenu;
252 - });
275 + }).then((result) => {
276 + context.close();
277 + // Keep surfacing unexpected failures as unhandled rejections.
278 + if (!AsyncResult.isSuccess(result)) throw Cause.squash(result.cause);
279 + });
280 + },
281 + );
282
283 const loadingDirectoriesRef = useRef(loadingDirectories);
284 const treeModelRef = useRef<ReturnType<typeof useFileTree>["model"] | null>(null);
256 - const dragMention = useMemo(
257 - () =>
258 - createFileTreeDragMentionController({
259 - deselect: (path) => treeModelRef.current?.getItem(path)?.deselect(),
260 - ...(hostFolder ? { mentionPath: (path: string) => joinHostPath(cwd, path) } : {}),
261 - }),
262 - [cwd, hostFolder],
263 - );
285 + const dragMention = useDragMentionController(cwd, hostFolder, treeModelRef);
286 const { model } = useFileTree({
287 composition: {
288 contextMenu: {
289 triggerMode: "right-click",
290 onOpen: (item, context) => {
269 - void showEntryContextMenuRef.current(item, context);
291 + showEntryContextMenu(item, context);
292 },
293 },
294 },