From ffbb36c3e6cc37697b8931e2c31a06a4562c8460 Mon Sep 17 00:00:00 2001 From: Marc Kelechava Date: Fri, 19 Dec 2025 09:15:57 -0800 Subject: [PATCH] Block duplication in nested loop save fix (#4342) --- .../workflows/editor/workflowEditorUtils.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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);