Merge pull request #5370 from xyflow/fix/xyhandle-end-events

Fix/xyhandle end events
This commit is contained in:
Moritz Klack
2025-06-27 21:11:04 +02:00
committed by GitHub
2 changed files with 25 additions and 18 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@xyflow/system': patch
---
Only fire connection end events if connection was started
+4 -2
View File
@@ -112,6 +112,7 @@ function onPointerDown(
}; };
function startConnection() { function startConnection() {
connectionStarted = true;
updateConnection(previousConnection); updateConnection(previousConnection);
onConnectStart?.(event, { nodeId, handleId, handleType }); onConnectStart?.(event, { nodeId, handleId, handleType });
} }
@@ -132,8 +133,6 @@ function onPointerDown(
} }
startConnection(); startConnection();
connectionStarted = nextConnectionStarted;
} }
if (!getFromHandle() || !fromHandle) { if (!getFromHandle() || !fromHandle) {
@@ -208,6 +207,7 @@ function onPointerDown(
} }
function onPointerUp(event: MouseEvent | TouchEvent) { function onPointerUp(event: MouseEvent | TouchEvent) {
if (connectionStarted) {
if ((closestHandle || handleDomNode) && connection && isValid) { if ((closestHandle || handleDomNode) && connection && isValid) {
onConnect?.(connection); onConnect?.(connection);
} }
@@ -222,11 +222,13 @@ function onPointerDown(
...connectionState, ...connectionState,
toPosition: previousConnection.toHandle ? previousConnection.toPosition : null, toPosition: previousConnection.toHandle ? previousConnection.toPosition : null,
}; };
onConnectEnd?.(event, finalConnectionState); onConnectEnd?.(event, finalConnectionState);
if (edgeUpdaterType) { if (edgeUpdaterType) {
onReconnectEnd?.(event, finalConnectionState); onReconnectEnd?.(event, finalConnectionState);
} }
}
cancelConnection(); cancelConnection();
cancelAnimationFrame(autoPanId); cancelAnimationFrame(autoPanId);