Skip to content

Commit 69c4cbf

Browse files
perf(web): the open-in picker compiles without manual memoization
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 70d60e0 commit 69c4cbf

2 files changed

Lines changed: 43 additions & 49 deletions

File tree

‎apps/web/reactCompiledFiles.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,5 @@ export const REACT_COMPILED_FILES = [
9696
"apps/web/src/components/pullRequest/PullRequestDetailPanel.tsx",
9797
"apps/web/src/components/ThreadTerminalDrawer.tsx",
9898
"apps/web/src/components/settings/SettingsPanels.tsx",
99+
"apps/web/src/components/chat/OpenInPicker.tsx",
99100
] as const;

‎apps/web/src/components/chat/OpenInPicker.tsx‎

Lines changed: 42 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
type EnvironmentId,
77
type ResolvedKeybindingsConfig,
88
} from "@t3tools/contracts";
9-
import { memo, useCallback, useEffect, useMemo, useRef } from "react";
9+
import { memo, useEffect, useRef } from "react";
1010
import { isOpenFavoriteEditorShortcut, shortcutLabelForCommand } from "../../keybindings";
1111
import { usePreferredEditor } from "../../editorPreferences";
1212
import { editorLabelForPlatform } from "../../editorLabels";
@@ -203,6 +203,13 @@ function getOpenInIconClass(kind: OpenInOption["kind"]) {
203203
return cn(kind === "brand" ? "text-foreground opacity-100" : "text-muted-foreground");
204204
}
205205

206+
// Resolving filters and labels every known editor; the compiler would redo
207+
// it every render because the open command hooks follow it.
208+
function useOpenInOptions(editors: ReadonlyArray<EditorId>) {
209+
"use memo";
210+
return resolveOpenInOptions(navigator.platform, editors);
211+
}
212+
206213
export const OpenInPicker = memo(function OpenInPicker({
207214
environmentId,
208215
keybindings,
@@ -238,59 +245,45 @@ export const OpenInPicker = memo(function OpenInPicker({
238245
// the viewing machine, which only the desktop app can probe.
239246
const effectiveEditors = remote.mode === "local-exec" ? availableEditors : remoteCapableEditors;
240247
const [preferredEditor, setPreferredEditor] = usePreferredEditor(effectiveEditors);
241-
const options = useMemo(
242-
() => resolveOpenInOptions(navigator.platform, effectiveEditors),
243-
[effectiveEditors],
244-
);
248+
const options = useOpenInOptions(effectiveEditors);
245249
const primaryOption = options.find(({ value }) => value === preferredEditor) ?? null;
246250

247-
const openInEditor = useCallback(
248-
(editorId: EditorId | null) => {
249-
if (!openInCwd) return;
250-
const editor = editorId ?? preferredEditor;
251-
if (!editor) return;
252-
if (remote.mode === "remote-unavailable") return;
253-
if (remote.mode === "remote-links") {
254-
const url = buildRemoteOpenUrl({
255-
editor,
256-
host: remote.host.host,
257-
absolutePath: openInCwd,
258-
});
259-
if (url === undefined) return;
260-
// Only record hint-seen/preferred when the shell actually accepted
261-
// the URL (an older desktop build can refuse the editor scheme).
262-
void openRemoteEditorUrl(url).then((opened) => {
263-
if (!opened) return;
264-
markRemoteHintSeen();
265-
setPreferredEditor(editor);
266-
});
267-
return;
268-
}
269-
if (!readEnvironmentScope(environmentId, AuthOrchestrationOperateScope)) return;
270-
const result = openInEditorMutation({
271-
environmentId,
272-
input: {
273-
cwd: openInCwd,
274-
editor,
275-
},
251+
const openInEditor = (editorId: EditorId | null) => {
252+
if (!openInCwd) return;
253+
const editor = editorId ?? preferredEditor;
254+
if (!editor) return;
255+
if (remote.mode === "remote-unavailable") return;
256+
if (remote.mode === "remote-links") {
257+
const url = buildRemoteOpenUrl({
258+
editor,
259+
host: remote.host.host,
260+
absolutePath: openInCwd,
276261
});
277-
setPreferredEditor(editor);
278-
return result;
279-
},
280-
[
262+
if (url === undefined) return;
263+
// Only record hint-seen/preferred when the shell actually accepted
264+
// the URL (an older desktop build can refuse the editor scheme).
265+
void openRemoteEditorUrl(url).then((opened) => {
266+
if (!opened) return;
267+
markRemoteHintSeen();
268+
setPreferredEditor(editor);
269+
});
270+
return;
271+
}
272+
if (!readEnvironmentScope(environmentId, AuthOrchestrationOperateScope)) return;
273+
const result = openInEditorMutation({
281274
environmentId,
282-
markRemoteHintSeen,
283-
openInCwd,
284-
openInEditorMutation,
285-
preferredEditor,
286-
remote,
287-
setPreferredEditor,
288-
],
289-
);
275+
input: {
276+
cwd: openInCwd,
277+
editor,
278+
},
279+
});
280+
setPreferredEditor(editor);
281+
return result;
282+
};
290283

291-
const openFavoriteEditorShortcutLabel = useMemo(
292-
() => shortcutLabelForCommand(keybindings, "editor.openFavorite"),
293-
[keybindings],
284+
const openFavoriteEditorShortcutLabel = shortcutLabelForCommand(
285+
keybindings,
286+
"editor.openFavorite",
294287
);
295288

296289
useEffect(() => {

0 commit comments

Comments
 (0)