The best way to control Claude Code, Codex and more from any computer or phone
fix(web): open editors when saving their preference fails (#34308)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
Romil committed
Nov 15, 2026 at 06:19 UTC
2137f360e6ba189368dc6273e7ec2f2a26da9287
2 files changed
+34
-2
apps/web/src/editorPreferences.test.ts
+21
@@ -67,3 +67,24 @@ it("checks revocation and regrant when a retained editor callback is invoked", a
67
});
68
expect(state.setPreference).toHaveBeenCalledTimes(1);
69
});
70
+
71
+it.each(["read", "write"] as const)(
72
+ "opens an available editor when its preference %s fails",
73
+ async (operation) => {
74
+ state.allowed.add(secondary);
75
+ const preference = operation === "read" ? state.getPreference : state.setPreference;
76
+ preference.mockImplementationOnce(() => {
77
+ throw new Error("Preference storage unavailable");
78
+ });
79
+ using _warnings = vi.spyOn(console, "warn").mockImplementation(() => undefined);
80
+ const open = useOpenInPreferredEditor(secondary, ["vscode"]);
81
+ await expect(open("/work/readme.md:5")).resolves.toMatchObject({
82
+ _tag: "Success",
83
+ value: "vscode",
84
+ });
85
+ expect(state.run).toHaveBeenCalledExactlyOnceWith({
86
+ environmentId: secondary,
87
+ input: { cwd: "/work/readme.md:5", editor: "vscode" },
88
+ });
89
+ },
90
+);
apps/web/src/editorPreferences.ts
+13
-2
@@ -57,10 +57,21 @@ export function usePreferredEditor(availableEditors: ReadonlyArray<EditorId>) {
57
58
function resolveAndPersistPreferredEditor(availableEditors: readonly EditorId[]): EditorId | null {
59
const availableEditorIds = new Set(availableEditors);
60
- const stored = getLocalStorageItem(LAST_EDITOR_KEY, EditorId);
60
+ let stored: EditorId | null = null;
61
+ try {
62
+ stored = getLocalStorageItem(LAST_EDITOR_KEY, EditorId);
63
+ } catch (error) {
64
+ console.warn("Could not read the preferred editor.", error);
65
+ }
66
if (stored && availableEditorIds.has(stored)) return stored;
67
const editor = EDITORS.find((editor) => availableEditorIds.has(editor.id))?.id ?? null;
63
- if (editor) setLocalStorageItem(LAST_EDITOR_KEY, editor, EditorId);
68
+ if (editor) {
69
+ try {
70
+ setLocalStorageItem(LAST_EDITOR_KEY, editor, EditorId);
71
+ } catch (error) {
72
+ console.warn("Could not save the preferred editor.", error);
73
+ }
74
+ }
75
return editor ?? null;
76
}
77