fix(web): harden typed SPA chat lifecycle

Co-Authored-By: Claude Haiku 4.5 <[email protected]>
This commit is contained in:
shaggy (mosaic-dev box)
2026-08-10 00:24:20 -05:00
co-authored by Claude Haiku 4.5
parent b2e005f2b4
commit caebf9ef70
20 changed files with 1778 additions and 125 deletions
+6 -6
View File
@@ -16,12 +16,12 @@ export function getSocket(): ChatSocket {
transports: ['websocket', 'polling'],
}) as unknown as ChatSocket;
// Reset singleton reference when socket is fully closed so the next
// getSocket() call creates a fresh instance instead of returning a
// closed/dead socket.
socket.on('disconnect', () => {
socket = null;
});
// A transient `disconnect` (network blip, server restart) must NOT null
// the singleton: socket.io-client auto-reconnects this same instance,
// and its listeners stay registered across that reconnect. Nulling here
// previously orphaned those listeners on the next getSocket() call by
// handing back a brand-new, unconnected instance. Only destroySocket()
// (an explicit, intentional teardown) may reset the singleton.
}
return socket;
}