diff --git a/skyvern-frontend/src/routes/workflows/editor/workflowEditorUtils.ts b/skyvern-frontend/src/routes/workflows/editor/workflowEditorUtils.ts index 37666bfd..a11ea28a 100644 --- a/skyvern-frontend/src/routes/workflows/editor/workflowEditorUtils.ts +++ b/skyvern-frontend/src/routes/workflows/editor/workflowEditorUtils.ts @@ -2352,6 +2352,19 @@ function getOrderedChildrenBlocks( return false; }; + // This prevents nested loop children from being added to the parent loop. + const isInsideIncludedLoop = (nodeId: string): boolean => { + let current = nodesById.get(nodeId); + while (current?.parentId) { + const parent = nodesById.get(current.parentId); + if (parent?.type === "loop" && includedIds.has(parent.id)) { + return true; + } + current = parent; + } + return false; + }; + const parentNode = nodes.find((node) => node.id === parentId); if (!parentNode) { return []; @@ -2410,6 +2423,9 @@ function getOrderedChildrenBlocks( if (!hasAncestor(node.id, parentId)) { return; } + if (isInsideIncludedLoop(node.id)) { + return; + } if (node.type === "loop") { const loopChildren = getOrderedChildrenBlocks(nodes, edges, node.id);