From d8905e0dfae56c3631101adcc3edfd54ab9987a8 Mon Sep 17 00:00:00 2001 From: Josh Hawkins <32435876+hawkeye217@users.noreply.github.com> Date: Thu, 7 May 2026 12:36:50 -0500 Subject: [PATCH] fix duplicate websocket messages from zombie connection under react strict mode detach ws event handlers before close() in WsProvider cleanup so a CONNECTING socket's deferred onclose can't schedule a reconnect after the next mount resets the unmounted guard, which was spawning a second live ws and duplicating every message --- web/src/api/WsProvider.tsx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/web/src/api/WsProvider.tsx b/web/src/api/WsProvider.tsx index 4e4f72490b..d00772f9d5 100644 --- a/web/src/api/WsProvider.tsx +++ b/web/src/api/WsProvider.tsx @@ -56,7 +56,14 @@ export function WsProvider({ children }: { children: ReactNode }) { if (reconnectTimer.current) { clearTimeout(reconnectTimer.current); } - wsRef.current?.close(); + const ws = wsRef.current; + if (ws) { + ws.onopen = null; + ws.onmessage = null; + ws.onclose = null; + ws.onerror = null; + ws.close(); + } resetWsStore(); }; }, [wsUrl]);