The best way to control Claude Code, Codex and more from any computer or phone
fix(web): device tools keep the typed text when a command fails (#28323)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Victor Vogel committed
Nov 1, 2026 at 16:04 UTC
09ace626bb0f920662e6e010aad9698a273f5404
4 files changed
+77
-18
apps/web/src/components/device/DeviceToolsPanel.browser.test.tsx
new
+54
@@ -0,0 +1,54 @@
1
+import type { DeviceSummary } from "@t3tools/contracts";
2
+import { expect, it, vi } from "vite-plus/test";
3
+import { userEvent } from "vite-plus/test/browser";
4
+
5
+import { act, render } from "../../../test/render";
6
+import { DeviceToolsPanel } from "./DeviceToolsPanel";
7
+import type { DeviceControls } from "./useDeviceControls";
8
+
9
+const device: DeviceSummary = {
10
+ hostId: "local",
11
+ id: "emulator",
12
+ name: "Pixel",
13
+ platform: "android",
14
+ version: "Android 15",
15
+ booted: true,
16
+ physical: false,
17
+};
18
+
19
+it("keeps a typed URL until opening it succeeds", async () => {
20
+ const run = vi
21
+ .fn<DeviceControls["act"]>()
22
+ .mockResolvedValueOnce(false)
23
+ .mockResolvedValueOnce(true);
24
+ const controls: DeviceControls = {
25
+ detail: null,
26
+ pending: false,
27
+ error: null,
28
+ act: run,
29
+ disabled: false,
30
+ foregroundApp: null,
31
+ };
32
+ await using screen = await render(
33
+ <DeviceToolsPanel
34
+ controls={controls}
35
+ hostDiagnostics={undefined}
36
+ device={device}
37
+ access={null}
38
+ axOverlay={false}
39
+ onAxOverlayChange={() => {}}
40
+ onClose={() => {}}
41
+ />,
42
+ );
43
+ const url = "myapp://settings";
44
+ const field = screen.getByPlaceholder("https://… or myapp://");
45
+ const open = screen.getByRole("button", { name: "Open" });
46
+
47
+ await userEvent.fill(field, url);
48
+ await userEvent.click(open);
49
+ await act(() => run.mock.results[0]?.value);
50
+ await expect.element(field).toHaveValue(url);
51
+
52
+ await userEvent.click(open);
53
+ await expect.element(field).toHaveValue("");
54
+});
apps/web/src/components/device/DeviceToolsPanel.tsx
+10
-8
@@ -312,7 +312,7 @@ export function DeviceToolsPanel(props: {
312
onSubmit={(payload) =>
313
foregroundApp
314
? act({ type: "sendPush", appId: foregroundApp.id, payload })
315
- : Promise.resolve()
315
+ : Promise.resolve(false)
316
}
317
/>
318
{!foregroundApp ? (
@@ -349,7 +349,7 @@ function SwitchRow(props: {
349
readonly label: string;
350
readonly checked: boolean | undefined;
351
readonly disabled: boolean;
352
- readonly onChange: (value: boolean) => Promise<void>;
352
+ readonly onChange: (value: boolean) => Promise<unknown>;
353
}) {
354
return (
355
<Row label={props.label}>
@@ -370,7 +370,7 @@ function ChoiceSelect<V extends string>(props: {
370
readonly options: ReadonlyArray<{ readonly value: V; readonly label: string }>;
371
readonly disabled: boolean;
372
readonly placeholder?: string;
373
- readonly onChange: (value: V) => Promise<void>;
373
+ readonly onChange: (value: V) => Promise<unknown>;
374
}) {
375
const current = props.options.find((option) => option.value === props.value);
376
return (
@@ -405,13 +405,15 @@ function SubmitRow(props: {
405
readonly placeholder: string;
406
readonly action: string;
407
readonly disabled: boolean;
408
- readonly onSubmit: (value: string) => Promise<void>;
408
+ readonly onSubmit: (value: string) => Promise<boolean>;
409
}) {
410
const [value, setValue] = useState("");
411
const submit = () => {
412
const trimmed = value.trim();
413
if (!trimmed) return;
414
- void props.onSubmit(trimmed).then(() => setValue(""));
414
+ void props.onSubmit(trimmed).then((sent) => {
415
+ if (sent) setValue("");
416
+ });
417
};
418
return (
419
<form
@@ -445,8 +447,8 @@ function SubmitRow(props: {
447
function LocationSection(props: {
448
readonly disabled: boolean;
449
readonly canClear: boolean;
448
- readonly onSet: (latitude: number, longitude: number) => Promise<void>;
449
- readonly onClear: () => Promise<void>;
450
+ readonly onSet: (latitude: number, longitude: number) => Promise<unknown>;
451
+ readonly onClear: () => Promise<unknown>;
452
}) {
453
const [latitude, setLatitude] = useState("");
454
const [longitude, setLongitude] = useState("");
@@ -541,7 +543,7 @@ function PermissionsSection(props: {
543
appId: string,
544
permission: DevicePermission,
545
decision: "grant" | "revoke" | "reset",
544
- ) => Promise<void>;
546
+ ) => Promise<unknown>;
547
}) {
548
const [appId, setAppId] = useState("");
549
const [permission, setPermission] = useState<DevicePermission>("camera");
apps/web/src/components/device/useDeviceControls.browser.test.tsx
+8
-6
@@ -116,21 +116,23 @@ it("serializes rapid actions and retains confirmed settings while pending or aft
116
await vi.waitFor(() => expect(controls.detail?.settings.appearance).toBe("light"));
117
const response = deferred();
118
action.mockReturnValueOnce(response.promise);
119
- let pending!: Promise<void>;
119
+ let pending!: Promise<boolean>;
120
await act(async () => {
121
pending = controls.act({ type: "setAppearance", value: "dark" });
122
- await controls.act({ type: "setAppearance", value: "light" });
122
+ expect(await controls.act({ type: "setAppearance", value: "light" })).toBe(false);
123
});
124
expect(action).toHaveBeenCalledOnce();
125
expect(controls.disabled).toBe(true);
126
expect(controls.detail?.settings.appearance).toBe("light");
127
await act(async () => {
128
response.resolve(snapshot("dark"));
129
- await pending;
129
+ expect(await pending).toBe(true);
130
});
131
expect(controls.detail?.settings.appearance).toBe("dark");
132
action.mockResolvedValueOnce({ _tag: "Failure", cause: offline });
133
- await act(async () => controls.act({ type: "setAppearance", value: "light" }));
133
+ await act(async () => {
134
+ expect(await controls.act({ type: "setAppearance", value: "light" })).toBe(false);
135
+ });
136
expect(controls.detail?.settings.appearance).toBe("dark");
137
expect(controls.error).toBe("Device offline");
138
expect(controls.disabled).toBe(false);
@@ -142,7 +144,7 @@ it("confirms settings again after a command sent before the panel reopened", asy
144
await vi.waitFor(() => expect(controls.detail).not.toBeNull());
145
const response = deferred();
146
action.mockReturnValueOnce(response.promise);
145
- let pending!: Promise<void>;
147
+ let pending!: Promise<boolean>;
148
await act(async () => {
149
pending = controls.act({ type: "setAppearance", value: "dark" });
150
});
@@ -174,7 +176,7 @@ it("does not let a read sent before an action overwrite the action's answer", as
176
await screen.rerender(view(true));
177
await vi.waitFor(() => expect(read).toHaveBeenCalledTimes(2));
178
action.mockResolvedValueOnce(snapshot("dark"));
177
- let pending!: Promise<void>;
179
+ let pending!: Promise<boolean>;
180
await act(async () => {
181
pending = controls.act({ type: "setAppearance", value: "dark" });
182
});
apps/web/src/components/device/useDeviceControls.ts
+5
-4
@@ -39,7 +39,7 @@ export function useDeviceControls(options: {
39
40
const available = detail !== null && visible;
41
const act = async (body: ActionBody) => {
42
- if (busy.current || !available) return;
42
+ if (busy.current || !available) return false;
43
busy.current = true;
44
setPending(true);
45
setView((current) => ({ ...current, error: null }));
@@ -47,13 +47,14 @@ export function useDeviceControls(options: {
47
environmentId,
48
input: { hostId, deviceId, ...body } as DeviceActionInput,
49
})
50
- .then((result) =>
50
+ .then((result) => {
51
setView((current) =>
52
result._tag === "Success"
53
? { detail: result.value, error: null }
54
: { ...current, error: formatEnvironmentQueryError(result.cause) },
55
- ),
56
- )
55
+ );
56
+ return result._tag === "Success";
57
+ })
58
.finally(() => {
59
busy.current = false;
60
setPending(false);