Browse Source

fix: cache router/switch passthrough results to fix multi-type data loss

When a router node had multiple output edges to the same downstream node
(e.g., passing both text and image), only the first edge type received
data. The shared _visited set prevented the router from being traversed
a second time, causing subsequent edge types to get empty results.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
handoff-20260429-1057
shrimbly 4 months ago
parent
commit
532231d2ef
  1. 13
      src/store/utils/connectedInputs.ts

13
src/store/utils/connectedInputs.ts

@ -166,6 +166,11 @@ export function getConnectedInputsPure(
});
}
// Cache passthrough node results so multiple edges from the same router/switch
// all receive correct data (the _visited set prevents re-traversal, so we cache
// the result from the first traversal and reuse it for subsequent edges).
const passthroughCache = new Map<string, ConnectedInputs>();
edges
.filter((edge) => edge.target === nodeId)
.forEach((edge) => {
@ -177,7 +182,9 @@ export function getConnectedInputsPure(
// Router passthrough — traverse upstream to find actual data source
if (sourceNode.type === "router") {
const routerInputs = getConnectedInputsPure(sourceNode.id, nodes, edges, _visited, dimmedNodeIds);
const routerInputs = passthroughCache.get(sourceNode.id)
?? getConnectedInputsPure(sourceNode.id, nodes, edges, _visited, dimmedNodeIds);
passthroughCache.set(sourceNode.id, routerInputs);
// Determine which type this edge carries based on the source handle
const edgeType = edge.sourceHandle; // Will be "image", "text", "video", "audio", "3d", or "easeCurve"
@ -210,7 +217,9 @@ export function getConnectedInputsPure(
}
// Enabled switch: recursively get upstream data (same pattern as router)
const switchInputs = getConnectedInputsPure(sourceNode.id, nodes, edges, _visited, dimmedNodeIds);
const switchInputs = passthroughCache.get(sourceNode.id)
?? getConnectedInputsPure(sourceNode.id, nodes, edges, _visited, dimmedNodeIds);
passthroughCache.set(sourceNode.id, switchInputs);
const edgeType = switchData.inputType;
if (edgeType === "image") {

Loading…
Cancel
Save