From 80e0213842518b7233253ed9c00d2f0679bb81e1 Mon Sep 17 00:00:00 2001 From: 1AhmedYasser <26207361+1AhmedYasser@users.noreply.github.com> Date: Fri, 12 Jun 2026 15:32:52 +0300 Subject: [PATCH] fix(1062): Fixed Loop Target Layout Breaking Upstream Nodes --- GUI/src/hooks/flow/useEdgeAdd.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/GUI/src/hooks/flow/useEdgeAdd.ts b/GUI/src/hooks/flow/useEdgeAdd.ts index 95e6bcb98..0c6c47aef 100644 --- a/GUI/src/hooks/flow/useEdgeAdd.ts +++ b/GUI/src/hooks/flow/useEdgeAdd.ts @@ -114,7 +114,16 @@ function useEdgeAdd(id: string) { let newEdges: Edge[] = []; setEdges((edges) => { - newEdges = edges.filter((e) => e.id !== id).concat([sourceEdge], targetEdge ?? [], ghostEdges); + const edgeIndex = edges.findIndex((e) => e.id === id); + const remainingEdges = edges.filter((e) => e.id !== id); + const insertIndex = edgeIndex === -1 ? remainingEdges.length : edgeIndex; + newEdges = [ + ...remainingEdges.slice(0, insertIndex), + sourceEdge, + ...(targetEdge ? [targetEdge] : []), + ...ghostEdges, + ...remainingEdges.slice(insertIndex), + ]; return newEdges; });