Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

fix(realtime): re-subscribe WS handlers when client reconnects (#580)

LinYushen21484e506aca
diff --git a/packages/core/realtime/provider.tsx b/packages/core/realtime/provider.tsx
index 44917cfe9c..5c368746ab 100644
--- a/packages/core/realtime/provider.tsx
+++ b/packages/core/realtime/provider.tsx
@@ -5,7 +5,6 @@ import {
useContext,
useEffect,
useState,
- useRef,
useCallback,
type ReactNode,
} from "react";
@@ -51,7 +50,6 @@ export function WSProvider({
const user = authStore((s) => s.user);
const workspace = workspaceStore((s) => s.workspace);
const [wsClient, setWsClient] = useState<WSClient | null>(null);
- const wsRef = useRef<WSClient | null>(null);
useEffect(() => {
if (!user || !workspace) return;
@@ -61,13 +59,11 @@ export function WSProvider({
const ws = new WSClient(wsUrl, { logger: createLogger("ws") });
ws.setAuth(token, workspace.id);
- wsRef.current = ws;
setWsClient(ws);
ws.connect();
return () => {
ws.disconnect();
- wsRef.current = null;
setWsClient(null);
};
}, [user, workspace, wsUrl, storage]);
@@ -79,20 +75,18 @@ export function WSProvider({
const subscribe = useCallback(
(event: WSEventType, handler: EventHandler) => {
- const ws = wsRef.current;
- if (!ws) return () => {};
- return ws.on(event, handler);
+ if (!wsClient) return () => {};
+ return wsClient.on(event, handler);
},
- [],
+ [wsClient],
);
const onReconnectCb = useCallback(
(callback: () => void) => {
- const ws = wsRef.current;
- if (!ws) return () => {};
- return ws.onReconnect(callback);
+ if (!wsClient) return () => {};
+ return wsClient.onReconnect(callback);
},
- [],
+ [wsClient],
);
return (