From 6c039be2caa5fd4a743fbf3485383db3570bde64 Mon Sep 17 00:00:00 2001 From: hjlarry Date: Fri, 10 Oct 2025 16:51:57 +0800 Subject: [PATCH] fix jump to other page not disconnect websocket --- .../collaboration/hooks/use-collaboration.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/web/app/components/workflow/collaboration/hooks/use-collaboration.ts b/web/app/components/workflow/collaboration/hooks/use-collaboration.ts index 31aad6e943..5d549e2baa 100644 --- a/web/app/components/workflow/collaboration/hooks/use-collaboration.ts +++ b/web/app/components/workflow/collaboration/hooks/use-collaboration.ts @@ -19,13 +19,24 @@ export function useCollaboration(appId: string, reactFlowStore?: any) { if (!appId) return let connectionId: string | null = null + let isUnmounted = false if (!cursorServiceRef.current) cursorServiceRef.current = new CursorService() const initCollaboration = async () => { - connectionId = await collaborationManager.connect(appId, reactFlowStore) - setState((prev: any) => ({ ...prev, appId, isConnected: collaborationManager.isConnected() })) + try { + const id = await collaborationManager.connect(appId, reactFlowStore) + if (isUnmounted) { + collaborationManager.disconnect(id) + return + } + connectionId = id + setState((prev: any) => ({ ...prev, appId, isConnected: collaborationManager.isConnected() })) + } + catch (error) { + console.error('Failed to initialize collaboration:', error) + } } initCollaboration() @@ -54,6 +65,7 @@ export function useCollaboration(appId: string, reactFlowStore?: any) { }) return () => { + isUnmounted = true unsubscribeStateChange() unsubscribeCursors() unsubscribeUsers()