diff --git a/packages/server/src/utils/index.ts b/packages/server/src/utils/index.ts index 8092fbd8..afd8e403 100644 --- a/packages/server/src/utils/index.ts +++ b/packages/server/src/utils/index.ts @@ -298,7 +298,9 @@ export const buildFlow = async ( nodeQueue.push({ nodeId: startingNodeIds[i], depth: 0 }) exploredNode[startingNodeIds[i]] = { remainingLoop: maxLoop, lastSeenDepth: 0 } } - + + const initializedNode: Set = new Set() + const nonDirectedGraph = constructGraphs(reactFlowNodes, reactFlowEdges, { isReversed: true }).graph while (nodeQueue.length) { const { nodeId, depth } = nodeQueue.shift() as INodeQueue @@ -384,6 +386,7 @@ export const buildFlow = async ( flowNodes[nodeIndex].data.instance = outputResult logger.debug(`[server]: Finished initializing ${reactFlowNode.data.label} (${reactFlowNode.data.id})`) + initializedNode.add(reactFlowNode.data.id) } } catch (e: any) { logger.error(e) @@ -406,6 +409,8 @@ export const buildFlow = async ( for (let i = 0; i < neighbourNodeIds.length; i += 1) { const neighNodeId = neighbourNodeIds[i] if (ignoreNodeIds.includes(neighNodeId)) continue + if (initializedNode.has(neighNodeId)) continue + if (nonDirectedGraph[neighNodeId].some((dependId) => !initializedNode.has(dependId))) continue // If nodeId has been seen, cycle detected if (Object.prototype.hasOwnProperty.call(exploredNode, neighNodeId)) { const { remainingLoop, lastSeenDepth } = exploredNode[neighNodeId]