Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/smooth-pillows-laugh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@vue-flow/core": patch
---

Defer connection lookup on edge update
17 changes: 14 additions & 3 deletions packages/core/src/store/actions.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -509,7 +510,13 @@ export function useActions(state: State, nodeLookup: ComputedRef<NodeLookup>, 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)

Expand All @@ -525,9 +532,13 @@ export function useActions(state: State, nodeLookup: ComputedRef<NodeLookup>, 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
}
Expand Down
Loading