From d1b187799cc452558fddf88ccfb08789b3ce09cf Mon Sep 17 00:00:00 2001 From: wbccb Date: Fri, 25 Oct 2024 21:20:54 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix(core):=20=E5=9C=A8=E6=B2=A1=E6=9C=89?= =?UTF-8?q?=E6=8B=96=E6=8B=BD=E7=9A=84=E6=83=85=E5=86=B5=E4=B8=8B=EF=BC=8C?= =?UTF-8?q?Control=E7=BB=84=E4=BB=B6=E7=AA=81=E7=84=B6=E9=94=80=E6=AF=81?= =?UTF-8?q?=EF=BC=8C=E4=B8=8D=E8=A7=A6=E5=8F=91cancelDrag(#1926)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/core/src/util/drag.ts | 12 ++++++++++++ packages/core/src/view/Control.tsx | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/core/src/util/drag.ts b/packages/core/src/util/drag.ts index 2aab60f8d..9bfe40ab9 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 } + + componentWillUnmount = () => { + 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..cef5f56fc 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.componentWillUnmount() } updateEdgePointByAnchors = () => { From fab2468be85f421dadf565ccd852b0242494b27e Mon Sep 17 00:00:00 2001 From: wbccb Date: Fri, 25 Oct 2024 21:49:37 +0800 Subject: [PATCH 2/2] =?UTF-8?q?chore(core):=20=E5=90=8D=E7=A7=B0=E6=9B=B4?= =?UTF-8?q?=E6=94=B9=20Control=E7=BB=84=E4=BB=B6componentWillUnmount=3D>de?= =?UTF-8?q?stroy?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/core/src/util/drag.ts | 2 +- packages/core/src/view/Control.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/core/src/util/drag.ts b/packages/core/src/util/drag.ts index 9bfe40ab9..fb10d71d0 100644 --- a/packages/core/src/util/drag.ts +++ b/packages/core/src/util/drag.ts @@ -202,7 +202,7 @@ export class StepDrag { this.isDragging = false } - componentWillUnmount = () => { + destroy = () => { if (this.isStartDragging) { // https://github.com/didi/LogicFlow/issues/1934 // https://github.com/didi/LogicFlow/issues/1926 diff --git a/packages/core/src/view/Control.tsx b/packages/core/src/view/Control.tsx index cef5f56fc..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.componentWillUnmount() + this.dragHandler.destroy() } updateEdgePointByAnchors = () => {