@devries-cameron20 / t3code-1 / commits / 41edad837f
Fork 0

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

perf(web): the file context menu hooks compile without manual memoization (#20683)

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

Julius Marminge committed Oct 16, 2026 at 21:50 UTC 41edad837f18a742816c4a5bbd1172448e156164
1 file changed +69 -75
apps/web/src/fileContextMenu.ts
+69 -75
@@ -4,7 +4,6 @@ import {
4 type EditorId,
5 type EnvironmentId,
6 } from "@t3tools/contracts";
7 -import { useCallback, useMemo } from "react";
7
8 import { resolveDiffPathForWorkspace } from "./diffFileActions";
9 import {
@@ -91,88 +90,83 @@ export function useFileContextMenu(environmentId: EnvironmentId | null) {
90 const openInEditor = useAtomCommand(shellEnvironment.openInEditor, { reportFailure: false });
91 const serverConfig = useAtomValue(serverEnvironment.configValueAtom(environmentId));
92
94 - return useMemo(() => {
95 - const availableEditors = serverConfig?.availableEditors ?? [];
96 - const capabilities: FileContextMenuCapabilities = {
97 - // The reveal wording comes from the server because on WSL the reveal can
98 - // run through Windows File Explorer even though the host reports Linux.
99 - revealLabel:
100 - environmentId !== null &&
101 - serverConfig?.shellRevealInFileManager === true &&
102 - serverConfig.availableEditors.includes("file-manager")
103 - ? serverConfig.shellRevealInFileManagerKind === undefined
104 - ? revealInFileExplorerLabelForOs(serverConfig.environment.platform.os)
105 - : revealInFileExplorerLabelForKind(serverConfig.shellRevealInFileManagerKind)
106 - : undefined,
107 - canOpenDefault: availableEditors.includes("file-manager"),
108 - editorIds: availableEditors,
109 - };
93 + const availableEditors = serverConfig?.availableEditors ?? [];
94 + const capabilities: FileContextMenuCapabilities = {
95 + // The reveal wording comes from the server because on WSL the reveal can
96 + // run through Windows File Explorer even though the host reports Linux.
97 + revealLabel:
98 + environmentId !== null &&
99 + serverConfig?.shellRevealInFileManager === true &&
100 + serverConfig.availableEditors.includes("file-manager")
101 + ? serverConfig.shellRevealInFileManagerKind === undefined
102 + ? revealInFileExplorerLabelForOs(serverConfig.environment.platform.os)
103 + : revealInFileExplorerLabelForKind(serverConfig.shellRevealInFileManagerKind)
104 + : undefined,
105 + canOpenDefault: availableEditors.includes("file-manager"),
106 + editorIds: availableEditors,
107 + };
108
111 - const activate = async (
112 - action: FileContextMenuAction,
113 - target: FileContextMenuTarget,
114 - ): Promise<void> => {
115 - const absolutePath = resolveFileContextMenuAbsolutePath(target);
116 - if (absolutePath === null || environmentId === null) return;
109 + const activate = async (
110 + action: FileContextMenuAction,
111 + target: FileContextMenuTarget,
112 + ): Promise<void> => {
113 + const absolutePath = resolveFileContextMenuAbsolutePath(target);
114 + if (absolutePath === null || environmentId === null) return;
115
118 - const reveal = action === "reveal-in-folder";
119 - const editor =
120 - action === "open" || reveal
121 - ? ("file-manager" as const)
122 - : (action.slice("editor:".length) as EditorId);
123 - if (action !== "open" && !reveal && !capabilities.editorIds.includes(editor)) return;
116 + const reveal = action === "reveal-in-folder";
117 + const editor =
118 + action === "open" || reveal
119 + ? ("file-manager" as const)
120 + : (action.slice("editor:".length) as EditorId);
121 + if (action !== "open" && !reveal && !capabilities.editorIds.includes(editor)) return;
122
125 - const result = await openInEditor({
126 - environmentId,
127 - input: { cwd: absolutePath, editor, ...(reveal ? { reveal: true } : {}) },
128 - });
129 - if (result._tag !== "Failure") return;
130 - toastManager.add({
131 - type: "error",
132 - title:
133 - action === "open"
134 - ? "Could not open file"
135 - : reveal
136 - ? "Unable to reveal file"
137 - : `Could not open in ${EDITOR_LABEL_BY_ID.get(editor) ?? editor}`,
138 - description: absolutePath,
139 - });
140 - };
123 + const result = await openInEditor({
124 + environmentId,
125 + input: { cwd: absolutePath, editor, ...(reveal ? { reveal: true } : {}) },
126 + });
127 + if (result._tag !== "Failure") return;
128 + toastManager.add({
129 + type: "error",
130 + title:
131 + action === "open"
132 + ? "Could not open file"
133 + : reveal
134 + ? "Unable to reveal file"
135 + : `Could not open in ${EDITOR_LABEL_BY_ID.get(editor) ?? editor}`,
136 + description: absolutePath,
137 + });
138 + };
139
142 - const show = async (
143 - target: FileContextMenuTarget,
144 - position?: { x: number; y: number },
145 - ): Promise<void> => {
146 - const api = readLocalApi();
147 - const items = buildFileContextMenuItems({
140 + const show = async (
141 + target: FileContextMenuTarget,
142 + position?: { x: number; y: number },
143 + ): Promise<void> => {
144 + const api = readLocalApi();
145 + const items = buildFileContextMenuItems({
146 + hasAbsolutePath: resolveFileContextMenuAbsolutePath(target) !== null,
147 + capabilities,
148 + });
149 + if (items.length === 0 || api === undefined) return;
150 + const clicked = await api.contextMenu.show(items, position);
151 + if (clicked === null) return;
152 + await activate(clicked as FileContextMenuAction, target);
153 + };
154 +
155 + return {
156 + buildItems: (target: FileContextMenuTarget) =>
157 + buildFileContextMenuItems({
158 hasAbsolutePath: resolveFileContextMenuAbsolutePath(target) !== null,
159 capabilities,
150 - });
151 - if (items.length === 0 || api === undefined) return;
152 - const clicked = await api.contextMenu.show(items, position);
153 - if (clicked === null) return;
154 - await activate(clicked as FileContextMenuAction, target);
155 - };
156 -
157 - return {
158 - buildItems: (target: FileContextMenuTarget) =>
159 - buildFileContextMenuItems({
160 - hasAbsolutePath: resolveFileContextMenuAbsolutePath(target) !== null,
161 - capabilities,
162 - }),
163 - capabilities,
164 - activate,
165 - show,
166 - };
167 - }, [environmentId, openInEditor, serverConfig]);
160 + }),
161 + capabilities,
162 + activate,
163 + show,
164 + };
165 }
166
167 export function useFileContextMenuHandler(environmentId: EnvironmentId | null) {
168 const contextMenu = useFileContextMenu(environmentId);
172 - return useCallback(
173 - (target: FileContextMenuTarget, event?: { clientX: number; clientY: number }) => {
174 - void contextMenu.show(target, event ? { x: event.clientX, y: event.clientY } : undefined);
175 - },
176 - [contextMenu],
177 - );
169 + return (target: FileContextMenuTarget, event?: { clientX: number; clientY: number }) => {
170 + void contextMenu.show(target, event ? { x: event.clientX, y: event.clientY } : undefined);
171 + };
172 }