diff --git a/web/app/components/workflow/hooks/use-workflow.ts b/web/app/components/workflow/hooks/use-workflow.ts index 62fe9ff409..7c08773ab4 100644 --- a/web/app/components/workflow/hooks/use-workflow.ts +++ b/web/app/components/workflow/hooks/use-workflow.ts @@ -60,7 +60,7 @@ export const useWorkflow = () => { setNodes(newNodes) }, [store]) - const getTreeLeafNodes = useCallback(() => { + const getTreeLeafNodes = useCallback((nodeId: string) => { const { getNodes, edges, @@ -73,6 +73,8 @@ export const useWorkflow = () => { const list: Node[] = [] const preOrder = (root: Node, callback: (node: Node) => void) => { + if (root.id === nodeId) + return const outgoers = getOutgoers(root, nodes, edges) if (outgoers.length) { @@ -81,7 +83,8 @@ export const useWorkflow = () => { }) } else { - callback(root) + if (root.id !== nodeId) + callback(root) } } preOrder(startNode, (node) => { diff --git a/web/app/components/workflow/nodes/_base/components/variable/var-reference-picker.tsx b/web/app/components/workflow/nodes/_base/components/variable/var-reference-picker.tsx index 958269b1b8..684a34eb4c 100644 --- a/web/app/components/workflow/nodes/_base/components/variable/var-reference-picker.tsx +++ b/web/app/components/workflow/nodes/_base/components/variable/var-reference-picker.tsx @@ -61,7 +61,7 @@ const VarReferencePicker: FC = ({ const [varKindType, setVarKindType] = useState(defaultVarKindType) const isConstant = isSupportConstantValue && varKindType === VarKindType.static const { getTreeLeafNodes, getBeforeNodesInSameBranch } = useWorkflow() - const availableNodes = onlyLeafNodeVar ? getTreeLeafNodes() : getBeforeNodesInSameBranch(nodeId) + const availableNodes = onlyLeafNodeVar ? getTreeLeafNodes(nodeId) : getBeforeNodesInSameBranch(nodeId) const outputVars = toNodeOutputVars(availableNodes, isChatMode, onlyVarType) const [open, setOpen] = useState(false) const hasValue = !isConstant && value.length > 0