diff --git a/packages/core/src/util/drag.ts b/packages/core/src/util/drag.ts index 2aab60f8d..fb10d71d0 100644 --- a/packages/core/src/util/drag.ts +++ b/packages/core/src/util/drag.ts @@ -201,4 +201,16 @@ export class StepDrag { this.onDragEnd({ event: undefined }) this.isDragging = false } + + destroy = () => { + if (this.isStartDragging) { + // https://github.com/didi/LogicFlow/issues/1934 + // https://github.com/didi/LogicFlow/issues/1926 + // cancelDrag()->onDragEnd()->updateEdgePointByAnchors()触发线的重新计算 + // 我们的本意是为了防止mousemove和mouseup没有及时被移除 + // 因此这里增加if(this.isStartDragging)的判断,isStartDragging=true代表没有触发handleMouseUp(),此时监听还没被移除 + // 在拖拽情况下(isStartDragging=true),此时注册了监听,在组件突然销毁时,强制触发cancelDrag进行监听事件的移除 + this.cancelDrag() + } + } } diff --git a/packages/core/src/view/Control.tsx b/packages/core/src/view/Control.tsx index 9fbce9c5b..01a7f07ea 100644 --- a/packages/core/src/view/Control.tsx +++ b/packages/core/src/view/Control.tsx @@ -57,7 +57,7 @@ export class ResizeControl extends Component< } componentWillUnmount() { - this.dragHandler.cancelDrag() + this.dragHandler.destroy() } updateEdgePointByAnchors = () => {