Skip to content

Commit

Permalink
fix(core): 在没有拖拽的情况下,Control组件突然销毁,不触发cancelDrag(didi#1926)
Browse files Browse the repository at this point in the history
  • Loading branch information
wbccb authored and menghany committed Nov 28, 2024
1 parent b8af3f5 commit 0b7f8ca
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 12 additions & 0 deletions packages/core/src/util/drag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
}
2 changes: 1 addition & 1 deletion packages/core/src/view/Control.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class ResizeControl extends Component<
}

componentWillUnmount() {
this.dragHandler.cancelDrag()
this.dragHandler.componentWillUnmount()
}

updateEdgePointByAnchors = () => {
Expand Down

0 comments on commit 0b7f8ca

Please sign in to comment.