@devries-cameron20 / t3code Mirror · read-only / commits / 37db94e520
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, 06:45 UTC

perf(web): the editor preference hooks compile without manual memoization (#20660)

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

Julius Marminge committed Oct 16, 2026 at 21:56 UTC 37db94e5204569b54aa773a50806ad57e09e22dd
1 file changed +55 -59
apps/web/src/editorPreferences.ts
+55 -59
@@ -14,7 +14,6 @@ import * as Cause from "effect/Cause";
14 import * as Schema from "effect/Schema";
15 import { AsyncResult } from "effect/reactivity";
16 import { getLocalStorageItem, setLocalStorageItem, useLocalStorage } from "./hooks/useLocalStorage";
17 -import { useCallback, useMemo } from "react";
17 import { shellEnvironment } from "./state/shell";
18 import { useAtomCommand } from "./state/use-atom-command";
19 import { readEnvironmentScope } from "./state/session";
@@ -48,10 +47,10 @@ export class PreferredEditorUnavailableError extends Schema.TaggedError<Preferre
47 export function usePreferredEditor(availableEditors: ReadonlyArray<EditorId>) {
48 const [lastEditor, setLastEditor] = useLocalStorage(LAST_EDITOR_KEY, null, EditorId);
49
51 - const effectiveEditor = useMemo(() => {
52 - if (lastEditor && availableEditors.includes(lastEditor)) return lastEditor;
53 - return EDITORS.find((editor) => availableEditors.includes(editor.id))?.id ?? null;
54 - }, [lastEditor, availableEditors]);
50 + const effectiveEditor =
51 + lastEditor && availableEditors.includes(lastEditor)
52 + ? lastEditor
53 + : (EDITORS.find((editor) => availableEditors.includes(editor.id))?.id ?? null);
54
55 return [effectiveEditor, setLastEditor] as const;
56 }
@@ -74,58 +73,55 @@ export function useOpenInPreferredEditor(
73 });
74 type OpenInEditorError = AtomCommandFailure<Awaited<ReturnType<typeof openInEditor>>>;
75
77 - return useCallback(
78 - async (
79 - targetPath: string,
80 - ): Promise<
81 - AtomCommandResult<
82 - EditorId,
83 - | OpenInEditorError
84 - | PreferredEditorEnvironmentRequiredError
85 - | PreferredEditorUnavailableError
86 - | EnvironmentAuthorizationError
87 - >
88 - > => {
89 - if (environmentId === null) {
90 - return AsyncResult.failure(
91 - Cause.fail(
92 - new PreferredEditorEnvironmentRequiredError({
93 - targetPath,
94 - }),
95 - ),
96 - );
97 - }
98 - if (!readEnvironmentScope(environmentId, AuthOrchestrationOperateScope)) {
99 - return AsyncResult.failure(
100 - Cause.fail(
101 - new EnvironmentAuthorizationError({
102 - requiredScope: AuthOrchestrationOperateScope,
103 - message: "This connection cannot open an editor on this environment.",
104 - }),
105 - ),
106 - );
107 - }
108 - const editor = resolveAndPersistPreferredEditor(availableEditors);
109 - if (!editor) {
110 - return AsyncResult.failure(
111 - Cause.fail(
112 - new PreferredEditorUnavailableError({
113 - environmentId,
114 - targetPath,
115 - availableEditorIds: availableEditors,
116 - }),
117 - ),
118 - );
119 - }
120 - const result = await openInEditor({
121 - environmentId,
122 - input: {
123 - cwd: targetPath,
124 - editor,
125 - },
126 - });
127 - return mapAtomCommandResult(result, () => editor);
128 - },
129 - [availableEditors, environmentId, openInEditor],
130 - );
76 + return async (
77 + targetPath: string,
78 + ): Promise<
79 + AtomCommandResult<
80 + EditorId,
81 + | OpenInEditorError
82 + | PreferredEditorEnvironmentRequiredError
83 + | PreferredEditorUnavailableError
84 + | EnvironmentAuthorizationError
85 + >
86 + > => {
87 + if (environmentId === null) {
88 + return AsyncResult.failure(
89 + Cause.fail(
90 + new PreferredEditorEnvironmentRequiredError({
91 + targetPath,
92 + }),
93 + ),
94 + );
95 + }
96 + if (!readEnvironmentScope(environmentId, AuthOrchestrationOperateScope)) {
97 + return AsyncResult.failure(
98 + Cause.fail(
99 + new EnvironmentAuthorizationError({
100 + requiredScope: AuthOrchestrationOperateScope,
101 + message: "This connection cannot open an editor on this environment.",
102 + }),
103 + ),
104 + );
105 + }
106 + const editor = resolveAndPersistPreferredEditor(availableEditors);
107 + if (!editor) {
108 + return AsyncResult.failure(
109 + Cause.fail(
110 + new PreferredEditorUnavailableError({
111 + environmentId,
112 + targetPath,
113 + availableEditorIds: availableEditors,
114 + }),
115 + ),
116 + );
117 + }
118 + const result = await openInEditor({
119 + environmentId,
120 + input: {
121 + cwd: targetPath,
122 + editor,
123 + },
124 + });
125 + return mapAtomCommandResult(result, () => editor);
126 + };
127 }