Browse Source

fix: ensure auto-routed prompts retain correct individual item text

The PromptNode text-sync effect can overwrite the per-item text set by
addNode before edge arrayItemIndex data is fully settled. Add a deferred
fix-up pass (setTimeout 0) that re-applies the correct text after React
effects have run.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
handoff-20260429-1057
shrimbly 4 months ago
parent
commit
23f6adabf9
  1. 14
      src/components/nodes/ArrayNode.tsx

14
src/components/nodes/ArrayNode.tsx

@ -125,12 +125,15 @@ export function ArrayNode({ id, data, selected }: NodeProps<ArrayNodeType>) {
const promptHeight = 220;
const verticalGap = 24;
const promptNodeIds: string[] = [];
items.forEach((item, index) => {
const promptNodeId = addNode(
"prompt",
{ x: baseX, y: baseY + index * (promptHeight + verticalGap) },
{ prompt: item }
);
promptNodeIds.push(promptNodeId);
// Pass the array item index directly as an edge data override
// instead of mutating selectedOutputIndex in a loop.
@ -144,7 +147,16 @@ export function ArrayNode({ id, data, selected }: NodeProps<ArrayNodeType>) {
{ arrayItemIndex: index }
);
});
}, [addNode, getNodes, id, onConnect, previewItems]);
// Deferred fix-up: the PromptNode text-sync effect may overwrite the
// individual item text before the edge arrayItemIndex data is fully
// settled. Re-apply the correct per-item text after effects have run.
setTimeout(() => {
items.forEach((item, index) => {
updateNodeData(promptNodeIds[index], { prompt: item });
});
}, 0);
}, [addNode, getNodes, id, onConnect, previewItems, updateNodeData]);
// Reset selection if it no longer points to a valid parsed item.
useEffect(() => {

Loading…
Cancel
Save