fix(workflow): clear loop/iteration metadata when pasting node outside container

When copying a node from inside a Loop/Iteration and pasting it outside,
the node was retaining loop-specific metadata (isInLoop, loop_id,
isInIteration, iteration_id, parentId), causing it to still be treated
as a loop child with restricted connections.

This fix clears these metadata fields when pasting a single node outside
of Loop/Iteration containers, ensuring the node behaves as an independent
workflow node.

Fixes #29835
This commit is contained in:
majiayu000 2025-12-22 15:17:13 +08:00
parent 42f7ecda12
commit 38e62c4eeb
1 changed files with 15 additions and 0 deletions

View File

@ -1609,6 +1609,8 @@ export const useNodesInteractions = () => {
else {
// single node paste
const selectedNode = nodes.find(node => node.selected)
let pastedToNestedBlock = false
if (selectedNode) {
const commonNestedDisallowPasteNodes = [
// end node only can be placed outermost layer
@ -1630,6 +1632,7 @@ export const useNodesInteractions = () => {
}
// set position base on parent node
newNode.position = getNestedNodePosition(newNode, selectedNode)
pastedToNestedBlock = true
}
else if (selectedNode.data.type === BlockEnum.Loop) {
newNode.data.isInLoop = true
@ -1641,8 +1644,20 @@ export const useNodesInteractions = () => {
}
// set position base on parent node
newNode.position = getNestedNodePosition(newNode, selectedNode)
pastedToNestedBlock = true
}
}
// Clear loop/iteration metadata when pasting outside nested blocks (fixes #29835)
// This ensures nodes copied from inside Loop/Iteration are properly independent
// when pasted outside
if (!pastedToNestedBlock) {
newNode.data.isInLoop = false
newNode.data.loop_id = undefined
newNode.data.isInIteration = false
newNode.data.iteration_id = undefined
newNode.parentId = undefined
}
}
nodesToPaste.push(newNode)