From 23f6adabf9b5765d1e5214258e52415286682202 Mon Sep 17 00:00:00 2001 From: shrimbly Date: Thu, 12 Mar 2026 08:26:33 +1300 Subject: [PATCH] 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 --- src/components/nodes/ArrayNode.tsx | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/components/nodes/ArrayNode.tsx b/src/components/nodes/ArrayNode.tsx index c1ffefb2..ce6ed0db 100644 --- a/src/components/nodes/ArrayNode.tsx +++ b/src/components/nodes/ArrayNode.tsx @@ -125,12 +125,15 @@ export function ArrayNode({ id, data, selected }: NodeProps) { 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) { { 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(() => {