From 9ad71b88b5903fd597413d2426708dd56a2b863a Mon Sep 17 00:00:00 2001 From: Emir Karabeg Date: Thu, 13 Feb 2025 13:59:51 -0800 Subject: [PATCH] Fix: conditional input handle error on delete --- .../sub-block/components/condition-input.tsx | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/w/[id]/components/workflow-block/components/sub-block/components/condition-input.tsx b/app/w/[id]/components/workflow-block/components/sub-block/components/condition-input.tsx index 500679b4e5..65a4c1b0dd 100644 --- a/app/w/[id]/components/workflow-block/components/sub-block/components/condition-input.tsx +++ b/app/w/[id]/components/workflow-block/components/sub-block/components/condition-input.tsx @@ -10,6 +10,7 @@ import { EnvVarDropdown, checkEnvVarTrigger } from '@/components/ui/env-var-drop import { TagDropdown, checkTagTrigger } from '@/components/ui/tag-dropdown' import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip' import { cn } from '@/lib/utils' +import { useWorkflowStore } from '@/stores/workflow/store' import { useSubBlockValue } from '../hooks/use-sub-block-value' interface ConditionalBlock { @@ -40,6 +41,8 @@ export function ConditionInput({ blockId, subBlockId, isConnecting }: ConditionI const editorRef = useRef(null) const [visualLineHeights, setVisualLineHeights] = useState<{ [key: string]: number[] }>({}) const updateNodeInternals = useUpdateNodeInternals() + const removeEdge = useWorkflowStore((state) => state.removeEdge) + const edges = useWorkflowStore((state) => state.edges) // Initialize conditional blocks with if and else blocks const [conditionalBlocks, setConditionalBlocks] = useState([ @@ -350,6 +353,13 @@ export function ConditionInput({ blockId, subBlockId, isConnecting }: ConditionI } const removeBlock = (id: string) => { + // Remove any associated edges before removing the block + edges.forEach((edge) => { + if (edge.sourceHandle?.startsWith(`condition-${id}`)) { + removeEdge(edge.id) + } + }) + if (conditionalBlocks.length === 1) return setConditionalBlocks((blocks) => updateBlockTitles(blocks.filter((block) => block.id !== id))) }