Skip to content

Automate browser based workflows with AI

Block duplication in nested loop save fix (#4342)

Marc Kelechavaffbb36c3e6cc
diff --git a/skyvern-frontend/src/routes/workflows/editor/workflowEditorUtils.ts b/skyvern-frontend/src/routes/workflows/editor/workflowEditorUtils.ts
index 37666bfd3..a11ea28aa 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);