From 03c5acdb0514a9ae1424404d5542f3583474cb87 Mon Sep 17 00:00:00 2001 From: shrimbly Date: Thu, 15 Jan 2026 23:38:04 +1300 Subject: [PATCH] Fix connection to find first unoccupied input handle When connecting to nodes with multiple input handles of the same type, now finds the first unoccupied handle instead of always targeting the first one. Returns null if all handles are occupied. Co-Authored-By: Claude Opus 4.5 --- src/components/WorkflowCanvas.tsx | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/components/WorkflowCanvas.tsx b/src/components/WorkflowCanvas.tsx index 425c798f..4d3c9205 100644 --- a/src/components/WorkflowCanvas.tsx +++ b/src/components/WorkflowCanvas.tsx @@ -333,12 +333,22 @@ export function WorkflowCanvas() { const nodeData = node.data as { inputSchema?: Array<{ name: string; type: string }> }; if (nodeData.inputSchema && nodeData.inputSchema.length > 0) { if (needInput) { - // Find first input handle matching the type + // Find input handles matching the type const matchingInputs = nodeData.inputSchema.filter(i => i.type === handleType); - if (matchingInputs.length > 0) { - // Return normalized handle ID, not schema name - // Always use indexed IDs (image-0, text-0) for schema inputs for consistency - return `${handleType}-0`; + const numHandles = matchingInputs.length; + if (numHandles > 0) { + // Find the first unoccupied indexed handle by checking existing edges + for (let i = 0; i < numHandles; i++) { + const candidateHandle = `${handleType}-${i}`; + const isOccupied = edges.some( + (edge) => edge.target === node.id && edge.targetHandle === candidateHandle + ); + if (!isOccupied) { + return candidateHandle; + } + } + // All handles are occupied + return null; } } // Output handle - check for video or image type @@ -425,7 +435,7 @@ export function WorkflowCanvas() { sourceHandleId: fromHandleId, }); }, - [screenToFlowPosition, nodes, handleConnect] + [screenToFlowPosition, nodes, edges, handleConnect] ); // Handle the splitGrid action - uses automated grid detection