Skip to content

Commit 2bacaa8

Browse files
committed
fix(core): only emit position changes if change occurred (#1939)
* fix(core): only emit position changes if a position change occurred Signed-off-by: braks <[email protected]> * chore(changeset): add Signed-off-by: braks <[email protected]> --------- Signed-off-by: braks <[email protected]>
1 parent a433f35 commit 2bacaa8

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

.changeset/selfish-cooks-jump.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@vue-flow/core": patch
3+
---
4+
5+
Only emit node position changes if a position change actually occurred.

packages/core/src/composables/useDrag.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ export function useDrag(params: UseDragParams) {
7474
let mousePosition: XYPosition = { x: 0, y: 0 }
7575
let dragEvent: MouseEvent | null = null
7676
let dragStarted = false
77+
let nodePositionsChanged = false
7778

7879
let autoPanId = 0
7980
let autoPanStarted = false
@@ -104,6 +105,8 @@ export function useDrag(params: UseDragParams) {
104105
return n
105106
})
106107

108+
nodePositionsChanged = nodePositionsChanged || hasChange
109+
107110
if (!hasChange) {
108111
return
109112
}
@@ -187,6 +190,8 @@ export function useDrag(params: UseDragParams) {
187190
return
188191
}
189192

193+
nodePositionsChanged = false
194+
190195
if (nodeDragThreshold.value === 0) {
191196
startDrag(event, nodeEl)
192197
}
@@ -244,7 +249,10 @@ export function useDrag(params: UseDragParams) {
244249
}
245250

246251
if (dragItems.length && !isClick) {
247-
updateNodePositions(dragItems, false, false)
252+
if (nodePositionsChanged) {
253+
updateNodePositions(dragItems, false, false)
254+
nodePositionsChanged = false
255+
}
248256

249257
const [currentNode, nodes] = getEventHandlerParams({
250258
id,

0 commit comments

Comments
 (0)