From 1f6b2d73ee7340e707a0e10e18fda911401697a3 Mon Sep 17 00:00:00 2001 From: Marquis Boyd Date: Fri, 20 Feb 2026 18:37:24 -0500 Subject: [PATCH] fix: auto-sync array input from upstream text updates --- src/components/nodes/ArrayNode.tsx | 34 ++++++++++++++++-------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/src/components/nodes/ArrayNode.tsx b/src/components/nodes/ArrayNode.tsx index 7b9b1adb..8e634ba2 100644 --- a/src/components/nodes/ArrayNode.tsx +++ b/src/components/nodes/ArrayNode.tsx @@ -6,6 +6,7 @@ import { BaseNode } from "./BaseNode"; import { useCommentNavigation } from "@/hooks/useCommentNavigation"; import { useWorkflowStore } from "@/store/workflowStore"; import { ArrayNodeData } from "@/types"; +import { getConnectedInputsPure } from "@/store/utils/connectedInputs"; import { parseTextToArray } from "@/utils/arrayParser"; type ArrayNodeType = Node; @@ -24,27 +25,28 @@ export function ArrayNode({ id, data, selected }: NodeProps) { const updateNodeData = useWorkflowStore((state) => state.updateNodeData); const addNode = useWorkflowStore((state) => state.addNode); const onConnect = useWorkflowStore((state) => state.onConnect); - const hasIncomingTextConnection = useWorkflowStore((state) => - state.edges.some((edge) => { - if (edge.target !== id) return false; - const handle = edge.targetHandle || "text"; - return handle === "text" || handle.startsWith("text-") || handle.includes("prompt"); - }) - ); - const connectedText = useWorkflowStore((state) => { - const hasIncoming = state.edges.some((edge) => { - if (edge.target !== id) return false; - const handle = edge.targetHandle || "text"; - return handle === "text" || handle.startsWith("text-") || handle.includes("prompt"); - }); - if (!hasIncoming) return null; - return state.getConnectedInputs(id).text; - }); + const nodes = useWorkflowStore((state) => state.nodes); + const edges = useWorkflowStore((state) => state.edges); const { setNodes, getNodes } = useReactFlow(); const lastSyncedInputRef = useRef(null); const lastDerivedWriteRef = useRef(null); const [showAdvanced, setShowAdvanced] = useState(false); + const hasIncomingTextConnection = useMemo( + () => + edges.some((edge) => { + if (edge.target !== id) return false; + const handle = edge.targetHandle || "text"; + return handle === "text" || handle.startsWith("text-") || handle.includes("prompt"); + }), + [edges, id] + ); + + const connectedText = useMemo(() => { + if (!hasIncomingTextConnection) return null; + return getConnectedInputsPure(id, nodes, edges).text; + }, [edges, hasIncomingTextConnection, id, nodes]); + // Pull upstream text into this node whenever the connected input changes. useEffect(() => { if (!hasIncomingTextConnection) {