fix(chat): prevent stale websocket close handler from triggering reconnect loop

This commit is contained in:
zwitschi committed 2026-08-15 16:28:32 +02:00
1 parent cef002862e
commit b6705e6dbd
2 files changed
+36 -5

No files matched your search

+19
View File
@@ -253,6 +253,25 @@ describe("WebSocket reconnect", () => {
expect(websocketInstances).toHaveLength(2);
expect(websocketInstances[1].url).toContain("room=lobby");
});
it("does not reconnect from a socket that was intentionally replaced", async () => {
vi.useFakeTimers();
window.switchRoom("lobby");
expect(websocketInstances).toHaveLength(1);
const replaced = websocketInstances[0];
// A room switch intentionally replaces the socket; the old socket must not
// schedule its own reconnect, otherwise history is re-pulled on a loop.
window.switchRoom("main");
expect(websocketInstances).toHaveLength(2);
expect(replaced.onclose).toBeNull();
replaced.onclose?.();
await vi.advanceTimersByTimeAsync(3000);
expect(websocketInstances).toHaveLength(2);
});
});
describe("URL resolution", () => {