Browse Source

fix(switch): resolve input type when creating Switch from connection menu

The menu path calls onConnect() directly, bypassing handleConnect's
resolveSwitchHandle. This left edges with targetHandle "generic-input"
instead of the actual type, causing inputType to be invalid, handles
to render without color, and downstream connections to fail validation.

- Set targetHandleId to actual type in handleMenuSelect Switch case
- Update Switch inputType immediately when created from menu
- Filter "generic-input" in derivedInputType as safety net

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
handoff-20260429-1057
shrimbly 5 months ago
parent
commit
c10cc100a6
  1. 12
      src/components/WorkflowCanvas.tsx
  2. 5
      src/components/nodes/SwitchNode.tsx

12
src/components/WorkflowCanvas.tsx

@ -961,12 +961,14 @@ export function WorkflowCanvas() {
sourceHandleIdForNewNode = handleType;
}
} else if (nodeType === "switch") {
// Switch accepts any type on generic-input, outputs match that type
targetHandleId = "generic-input";
// Switch input: use the actual type so the edge stores the correct handle type
// (onConnect bypasses resolveSwitchHandle, so we must resolve here)
targetHandleId = handleType || "generic-input";
if (handleType) {
updateNodeData(newNodeId, { inputType: handleType as HandleType });
}
// Switch outputs use dynamic handle IDs (switch entry IDs)
// For connection purposes, we'll connect to the first switch output
// The resolveSwitchHandle will update inputType when input connects
sourceHandleIdForNewNode = null; // Switch outputs are dynamic, no static handle ID
sourceHandleIdForNewNode = null;
} else if (handleType === "image") {
if (nodeType === "annotation" || nodeType === "output" || nodeType === "splitGrid" || nodeType === "outputGallery" || nodeType === "imageCompare") {
targetHandleId = "image";

5
src/components/nodes/SwitchNode.tsx

@ -26,7 +26,10 @@ export const SwitchNode = memo(({ id, data, selected }: NodeProps<WorkflowNode>)
// Derive inputType from incoming edge connection
const derivedInputType = useMemo(() => {
const inputEdge = edges.find((e) => e.target === id);
return inputEdge?.targetHandle as HandleType | undefined;
const handle = inputEdge?.targetHandle;
// "generic-input" means the edge hasn't been resolved to a real type yet
if (!handle || handle === "generic-input") return undefined;
return handle as HandleType;
}, [edges, id]);
// Update stored inputType when derived type changes

Loading…
Cancel
Save