Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): defer connection lookup #1793

Merged
merged 2 commits into from
Mar 13, 2025
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