diff --git a/web/app/components/workflow-app/hooks/use-workflow-init.ts b/web/app/components/workflow-app/hooks/use-workflow-init.ts index fb007c031f..ff0fd50e58 100644 --- a/web/app/components/workflow-app/hooks/use-workflow-init.ts +++ b/web/app/components/workflow-app/hooks/use-workflow-init.ts @@ -56,20 +56,6 @@ export const useWorkflowInit = () => { }) } - const populateCollaborationWithServerData = async (serverData: any) => { - const { nodesMap, edgesMap, loroDoc } = useCollaborationStore.getState() - serverData.graph.nodes?.forEach((node: any) => { - console.log('Setting node:', node.id, node) - nodesMap.set(node.id, node) - }) - - serverData.graph.edges?.forEach((edge: any) => { - console.log('Setting edge:', edge.id, edge) - edgesMap.set(edge.id, edge) - }) - loroDoc.commit() - } - const handleGetInitialWorkflowData = useCallback(async () => { try { const [res] = await Promise.all([ @@ -85,7 +71,6 @@ export const useWorkflowInit = () => { environmentVariables: res.environment_variables?.map(env => env.value_type === 'secret' ? { ...env, value: '[__HIDDEN__]' } : env) || [], conversationVariables: res.conversation_variables || [], }) - await populateCollaborationWithServerData(res) setSyncWorkflowDraftHash(res.hash) setIsLoading(false) } diff --git a/web/app/components/workflow-app/index.tsx b/web/app/components/workflow-app/index.tsx index 761a7f29c4..db404a7efc 100644 --- a/web/app/components/workflow-app/index.tsx +++ b/web/app/components/workflow-app/index.tsx @@ -23,6 +23,7 @@ import { } from '@/app/components/workflow/context' import { createWorkflowSlice } from './store/workflow/workflow-slice' import WorkflowAppMain from './components/workflow-main' +import { useCollaborationStore } from '@/app/components/workflow/store/collaboration-store' const WorkflowAppWithAdditionalContext = () => { const { @@ -32,15 +33,26 @@ const WorkflowAppWithAdditionalContext = () => { const { data: fileUploadConfigResponse } = useSWR({ url: '/files/upload' }, fetchFileUploadConfig) const nodesData = useMemo(() => { - if (data) - return initialNodes(data.graph.nodes, data.graph.edges) + if (data) { + const processedNodes = initialNodes(data.graph.nodes, data.graph.edges) + const { setNodes } = useCollaborationStore.getState() + setNodes(processedNodes) + + return processedNodes + } return [] }, [data]) - const edgesData = useMemo(() => { - if (data) - return initialEdges(data.graph.edges, data.graph.nodes) + const edgesData = useMemo(() => { + if (data) { + const processedEdges = initialEdges(data.graph.edges, data.graph.nodes) + + const { setEdges } = useCollaborationStore.getState() + setEdges(processedEdges) + + return processedEdges + } return [] }, [data]) diff --git a/web/app/components/workflow/store/collaboration-store.ts b/web/app/components/workflow/store/collaboration-store.ts index 649ae6a008..51fe6f1c30 100644 --- a/web/app/components/workflow/store/collaboration-store.ts +++ b/web/app/components/workflow/store/collaboration-store.ts @@ -94,15 +94,15 @@ export const useCollaborationStore = create((set, get) => ({ const oldNode = oldNodesMap.get(newNode.id) if (!oldNode) { // add - nodesMap.set(newNode.id, getPersistentNodeData(newNode)) + nodesMap.set(newNode.id, newNode) } - else { + else { const oldPersistentData = getPersistentNodeData(oldNode) const newPersistentData = getPersistentNodeData(newNode) if (!isEqual(oldPersistentData, newPersistentData)) { // update - nodesMap.set(newNode.id, newPersistentData) + nodesMap.set(newNode.id, newNode) } } })