Skip to content

Commit 4b964e1

Browse files
saphidclaude
andcommitted
fix(preview): a dropped stream withdraws its stale file picker
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 30084f0 commit 4b964e1

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

‎packages/client-runtime/src/preview/serverBrowserStream.test.ts‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,23 @@ describe("preview stream control", () => {
107107
expect(client.send({ type: "dialog", accept: false })).toBe(false);
108108
client.stop();
109109
});
110+
111+
it("withdraws an offered file picker when the stream drops", () => {
112+
const onFileChooser = vi.fn();
113+
const client = createPreviewStreamClient(target, {
114+
onFrame: vi.fn(),
115+
onFileChooser,
116+
onViewport: vi.fn(),
117+
onConnectedChange: vi.fn(),
118+
onUnauthorized: vi.fn(),
119+
});
120+
const socket = FakeSocket.current;
121+
socket.dispatchEvent(new Event("open"));
122+
socket.message(JSON.stringify({ type: "fileChooser", id: "c1", multiple: false, accept: "" }));
123+
socket.dispatchEvent(Object.assign(new Event("close"), { code: 1012 }));
124+
expect(onFileChooser).toHaveBeenLastCalledWith(null);
125+
client.stop();
126+
});
110127
});
111128

112129
describe("preview stream downloads", () => {

‎packages/client-runtime/src/preview/serverBrowserStream.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,11 @@ export function createPreviewStreamClient(
346346
if (socket !== ws) return;
347347
socket = null;
348348
control = null;
349+
// The server re-offers a picker still open, under a new id, when this viewer reattaches.
350+
if (fileChooser !== null) {
351+
fileChooser = null;
352+
events.onFileChooser?.(null);
353+
}
349354
if (opened) events.onConnectedChange(false);
350355
if (stopped) return;
351356
if (event.code === 4404) {

0 commit comments

Comments
 (0)