From 153f9a71fb69fc054a5d7c51d979bd8f926ccae2 Mon Sep 17 00:00:00 2001 From: braks <78412429+bcakmakoglu@users.noreply.github.com> Date: Thu, 13 Mar 2025 08:30:46 +0100 Subject: [PATCH 1/2] fix(core): defer connection lookup Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com> --- packages/core/src/store/actions.ts | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/packages/core/src/store/actions.ts b/packages/core/src/store/actions.ts index 882aac2ef..a88412282 100644 --- a/packages/core/src/store/actions.ts +++ b/packages/core/src/store/actions.ts @@ -1,5 +1,6 @@ import { zoomIdentity } from 'd3-zoom' import type { ComputedRef } from 'vue' +import { nextTick } from 'vue' import { until } from '@vueuse/core' import type { Actions, @@ -509,7 +510,13 @@ export function useActions(state: State, nodeLookup: ComputedRef, ed } const updateEdge: Actions['updateEdge'] = (oldEdge, newConnection, shouldReplaceId = true) => { - const prevEdge = findEdge(oldEdge.id)! + const prevEdge = findEdge(oldEdge.id) + + if (!prevEdge) { + return false + } + + const prevEdgeIndex = state.edges.indexOf(prevEdge) const newEdge = updateEdgeAction(oldEdge, newConnection, prevEdge, shouldReplaceId, state.hooks.error.trigger) @@ -525,9 +532,13 @@ export function useActions(state: State, nodeLookup: ComputedRef, ed state.edges, ) - state.edges.splice(state.edges.indexOf(prevEdge), 1, validEdge) + nextTick(() => { + state.edges = state.edges.map((edge, index) => (index === prevEdgeIndex ? validEdge : edge)) - updateConnectionLookup(state.connectionLookup, edgeLookup.value, [validEdge]) + nextTick(() => { + updateConnectionLookup(state.connectionLookup, edgeLookup.value, [validEdge]) + }) + }) return validEdge } From 96d787b7cf53a18f54fbc28e3ca24acec3e6488c Mon Sep 17 00:00:00 2001 From: braks <78412429+bcakmakoglu@users.noreply.github.com> Date: Thu, 13 Mar 2025 08:31:12 +0100 Subject: [PATCH 2/2] chore(changeset): add Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com> --- .changeset/smooth-pillows-laugh.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/smooth-pillows-laugh.md diff --git a/.changeset/smooth-pillows-laugh.md b/.changeset/smooth-pillows-laugh.md new file mode 100644 index 000000000..8b70ab4fa --- /dev/null +++ b/.changeset/smooth-pillows-laugh.md @@ -0,0 +1,5 @@ +--- +"@vue-flow/core": patch +--- + +Defer connection lookup on edge update