diff --git a/src/contexts/WebSocketContext.tsx b/src/contexts/WebSocketContext.tsx index 116da6b9..456c0761 100644 --- a/src/contexts/WebSocketContext.tsx +++ b/src/contexts/WebSocketContext.tsx @@ -36,8 +36,12 @@ const useWebSocketProviderState = (): WebSocketContextType => { const { token } = useAuth(); useEffect(() => { + // The cleanup below sets unmountedRef = true. Without this reset, every + // re-run of the effect (e.g. on token refresh) would short-circuit connect() + // at its unmounted guard and leave the socket permanently disconnected. + unmountedRef.current = false; connect(); - + return () => { unmountedRef.current = true; if (reconnectTimeoutRef.current) {