diff --git a/packages/web/src/__tests__/devtools-binding.test.ts b/packages/web/src/__tests__/devtools-binding.test.ts index 2e563530..9e28fcf3 100644 --- a/packages/web/src/__tests__/devtools-binding.test.ts +++ b/packages/web/src/__tests__/devtools-binding.test.ts @@ -115,6 +115,27 @@ describe("the devtools binding transport", () => { const { devtools, events } = setup(); devtools.receive(JSON.stringify({ kind: "open" })); + devtools.receive(JSON.stringify({ kind: "message", text: '{"type":"y"}' })); + + expect(events).toEqual(["open", 'message:{"type":"y"}']); + }); + + it("still delivers what the relay tags for the new socket after dropping the old one's", () => { + const { devtools, socket, sent } = setup(); + const first = sent[0]!.id; + socket.close(1000, "superseded"); + const events: string[] = []; + devtools.transport.open("ws://127.0.0.1:49152", { + open: () => events.push("open"), + message: (text) => events.push(`message:${text}`), + close: (code, reason) => events.push(`close:${code}:${reason}`), + error: (message) => events.push(`error:${message}`), + }); + const second = sent.filter((message) => message.kind === "open")[1]!.id; + + devtools.receive(JSON.stringify({ kind: "open", id: first })); + devtools.receive(JSON.stringify({ kind: "close", id: first, code: 1006, reason: "" })); + devtools.receive(JSON.stringify({ kind: "open", id: second })); expect(events).toEqual(["open"]); }); diff --git a/packages/web/src/browser/devtools-binding.ts b/packages/web/src/browser/devtools-binding.ts index dd7466fb..5eda9a86 100644 --- a/packages/web/src/browser/devtools-binding.ts +++ b/packages/web/src/browser/devtools-binding.ts @@ -10,7 +10,8 @@ import type { SocketEvents, Transport } from "../core/index.js"; * * Every message carries the `id` of the socket it is about, chosen by the page on `open`. The * relay echoes it, so a message queued for a socket the page has since replaced is dropped - * instead of reaching the new one. A message without an `id` goes to the active socket. + * instead of reaching the new one. A message without an `id` (an older relay, or `attachPage` + * closing the page's socket) goes to the active socket. */ export const createDevtoolsBindingTransport = ( sendToRelay: (json: string) => void,