Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): 在没有拖拽的情况下,Control组件突然销毁,不触发cancelDrag(#1926) #1938

Merged
merged 2 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}

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()
}
}
}
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.destroy()
}

updateEdgePointByAnchors = () => {
Expand Down