diff --git a/src/views/flow/vue-flow/adapter.js b/src/views/flow/vue-flow/adapter.js index 68aaa69..c3c66e1 100644 --- a/src/views/flow/vue-flow/adapter.js +++ b/src/views/flow/vue-flow/adapter.js @@ -791,10 +791,21 @@ export const createFlowFacade = (store) => { const group = store.findNode(groupId); const child = store.findNode(childId); if (!group || !child || GROUP_TYPES.has(child.data.flowType)) return; + const previousParentId = child.parentNode || child.data?.properties?.parentId; const graph = facade.getGraphData(); const groupData = graph.nodes.find((node) => node.id === groupId); const childData = graph.nodes.find((node) => node.id === childId); if (!groupData || !childData) return; + + // 节点从循环体外进入循环体后,原连线的两端已处于不同执行作用域,必须全部断开。 + // 在重新渲染父子结构前直接过滤图数据,可保证入边、出边和层级变更在同一次更新中完成。 + const enteringLoop = group.data.flowType === "loop" && previousParentId !== groupId; + if (enteringLoop) { + graph.edges = graph.edges.filter((edge) => ( + edge.sourceNodeId !== childId && edge.targetNodeId !== childId + )); + } + groupData.children = Array.from(new Set([...(groupData.children || []), childId])); childData.properties = { ...(childData.properties || {}), parentId: groupId }; if (dropCenter) {