@devries-cameron20 / t3code Mirror · read-only / commits / c65e488359
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 22, 12:00 UTC

fix(web): save settings fields only after an edit (#23427)

Co-authored-by: GPT-6.1 Sol <noreply@openai.com>

Victor Vogel committed Oct 30, 2026 at 15:46 UTC c65e4883596e6ca06c71176006b1b7fb61995a2e
2 files changed +45 -2
apps/web/src/hooks/useCommitOnBlur.browser.test.tsx new
+41
@@ -0,0 +1,41 @@
1 +import { describe, expect, it } from "vite-plus/test";
2 +import { userEvent } from "vite-plus/test/browser";
3 +
4 +import { render } from "../../test/render";
5 +import { DraftInput } from "../components/ui/draft-input";
6 +
7 +describe("settings draft commits", () => {
8 + it("preserves an external update when an untouched field loses focus", async () => {
9 + let saved = "~/";
10 + const commit = (next: string) => {
11 + saved = next;
12 + };
13 + await using screen = await render(<DraftInput value={saved} onCommit={commit} />);
14 + const input = screen.getByRole("textbox");
15 + await input.click();
16 +
17 + saved = "/projects";
18 + await screen.rerender(<DraftInput value={saved} onCommit={commit} />);
19 + await userEvent.tab();
20 +
21 + expect(saved).toBe("/projects");
22 + });
23 +
24 + it("preserves a saved edit when refocused before its server snapshot arrives", async () => {
25 + let saved = "~/";
26 + const commit = (next: string) => {
27 + saved = next;
28 + };
29 + await using screen = await render(<DraftInput value="~/" onCommit={commit} />);
30 + const input = screen.getByRole("textbox");
31 + await input.fill("/projects");
32 + await userEvent.tab();
33 + expect(saved).toBe("/projects");
34 +
35 + await input.click();
36 + await screen.rerender(<DraftInput value={saved} onCommit={commit} />);
37 + await userEvent.tab();
38 +
39 + expect(saved).toBe("/projects");
40 + });
41 +});
apps/web/src/hooks/useCommitOnBlur.ts
+4 -2
@@ -1,7 +1,8 @@
1 -import { type ChangeEvent, type KeyboardEvent, useState } from "react";
1 +import { type ChangeEvent, type KeyboardEvent, useRef, useState } from "react";
2
3 export function useCommitOnBlur(value: string, onCommit: (next: string) => void) {
4 const [draft, setDraft] = useState<string | null>(null);
5 + const valueOnFocus = useRef(value);
6
7 return {
8 value: draft ?? value,
@@ -9,12 +10,13 @@ export function useCommitOnBlur(value: string, onCommit: (next: string) => void)
10 setDraft(event.target.value);
11 },
12 onFocus: () => {
13 + valueOnFocus.current = value;
14 setDraft(value);
15 },
16 onBlur: () => {
17 const next = draft ?? value;
18 setDraft(null);
17 - if (next !== value) {
19 + if (next !== valueOnFocus.current && next !== value) {
20 onCommit(next);
21 }
22 },