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

fix(preview): a dropped stream withdraws its stale file picker (#29655)

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

Alex Southwell committed Nov 3, 2026 at 23:11 UTC c185d780fc3f5ad29695985f2f7f99428b414a73
2 files changed +34
packages/client-runtime/src/preview/serverBrowserStream.test.ts
+25
@@ -107,6 +107,31 @@ describe("preview stream control", () => {
107 expect(client.send({ type: "dialog", accept: false })).toBe(false);
108 client.stop();
109 });
110 +
111 + it("withdraws an offered file picker when the stream drops or stops", () => {
112 + const onFileChooser = vi.fn();
113 + const events = {
114 + onFrame: vi.fn(),
115 + onFileChooser,
116 + onViewport: vi.fn(),
117 + onConnectedChange: vi.fn(),
118 + onUnauthorized: vi.fn(),
119 + };
120 + const client = createPreviewStreamClient(target, events);
121 + const socket = FakeSocket.current;
122 + socket.dispatchEvent(new Event("open"));
123 + socket.message(JSON.stringify({ type: "fileChooser", id: "c1", multiple: false, accept: "" }));
124 + socket.dispatchEvent(Object.assign(new Event("close"), { code: 1012 }));
125 + expect(onFileChooser).toHaveBeenLastCalledWith(null);
126 + client.stop();
127 +
128 + const restarted = createPreviewStreamClient(target, events);
129 + FakeSocket.current.message(
130 + JSON.stringify({ type: "fileChooser", id: "c2", multiple: false, accept: "" }),
131 + );
132 + restarted.stop();
133 + expect(onFileChooser).toHaveBeenLastCalledWith(null);
134 + });
135 });
136
137 describe("preview stream downloads", () => {
packages/client-runtime/src/preview/serverBrowserStream.ts
+9
@@ -224,6 +224,13 @@ export function createPreviewStreamClient(
224 let control: PreviewStreamControl | null = null;
225 let fileChooser: string | null = null;
226
227 + // The server re-offers a picker still open, under a new id, when this viewer reattaches.
228 + const withdrawFileChooser = () => {
229 + if (fileChooser === null) return;
230 + fileChooser = null;
231 + events.onFileChooser?.(null);
232 + };
233 +
234 const connect = () => {
235 if (stopped) return;
236 const ws = new WebSocket(url);
@@ -346,6 +353,7 @@ export function createPreviewStreamClient(
353 if (socket !== ws) return;
354 socket = null;
355 control = null;
356 + withdrawFileChooser();
357 if (opened) events.onConnectedChange(false);
358 if (stopped) return;
359 if (event.code === 4404) {
@@ -385,6 +393,7 @@ export function createPreviewStreamClient(
393 const ws = socket;
394 socket = null;
395 control = null;
396 + withdrawFileChooser();
397 ws?.close();
398 },
399 };