From 0eea69b07d8245562c88ee28abb915381f944dd2 Mon Sep 17 00:00:00 2001 From: waleed Date: Sat, 31 Jan 2026 20:17:35 -0800 Subject: [PATCH] fix(lock): prevent duplicates inside locked containers via regenerateBlockIds 1. regenerateBlockIds now checks if existing parent is locked before keeping the block inside it. If parent is locked, the duplicate is placed outside (parentId cleared) instead of creating an inconsistent state. 2. Remove unnecessary effectivePermissions.canAdmin and potentialParentId from onNodeDragStart dependency array. Co-Authored-By: Claude Opus 4.5 --- .../workspace/[workspaceId]/w/[workflowId]/workflow.tsx | 9 +-------- apps/sim/stores/workflows/utils.ts | 5 +++-- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/apps/sim/app/workspace/[workspaceId]/w/[workflowId]/workflow.tsx b/apps/sim/app/workspace/[workspaceId]/w/[workflowId]/workflow.tsx index 1874bcab6..6240e0ac7 100644 --- a/apps/sim/app/workspace/[workspaceId]/w/[workflowId]/workflow.tsx +++ b/apps/sim/app/workspace/[workspaceId]/w/[workflowId]/workflow.tsx @@ -2889,14 +2889,7 @@ const WorkflowContent = React.memo(() => { } }) }, - [ - blocks, - setDragStartPosition, - getNodes, - potentialParentId, - setPotentialParentId, - effectivePermissions.canAdmin, - ] + [blocks, setDragStartPosition, getNodes, setPotentialParentId] ) /** Handles node drag stop to establish parent-child relationships. */ diff --git a/apps/sim/stores/workflows/utils.ts b/apps/sim/stores/workflows/utils.ts index b1d3805fa..18bf38fb1 100644 --- a/apps/sim/stores/workflows/utils.ts +++ b/apps/sim/stores/workflows/utils.ts @@ -511,14 +511,15 @@ export function regenerateBlockIds( parentId: newParentId, extent: 'parent', } - } else if (existingBlockNames[oldParentId]) { - // Parent exists in existing workflow - keep original parentId (block stays in same subflow) + } else if (existingBlockNames[oldParentId] && !existingBlockNames[oldParentId].locked) { + // Parent exists in existing workflow and is not locked - keep original parentId block.data = { ...block.data, parentId: oldParentId, extent: 'parent', } } else { + // Parent doesn't exist anywhere OR parent is locked - clear the relationship // Parent doesn't exist anywhere - clear the relationship block.data = { ...block.data, parentId: undefined, extent: undefined } }