fix(core): 在没有拖拽的情况下,Control组件突然销毁,不触发cancelDrag(#1926) #1938
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
fix #1934
fix #1926
问题发生的原因
为了解决
Control
组件意外销毁,但是没有及时释放监听事件的问题,在组件销毁时,强制触发了这导致一个问题
Control
组件,点击空白地方会隐藏Control
组件,从而触发componentWillUnmount
,从而触发cancelDrag()->onDragEnd()->updateEdgePointByAnchors()触发线的重新计算componentWillUnmount
,从而触发cancelDrag()->onDragEnd()->updateEdgePointByAnchors()触发线的重新计算自动触发计算逻辑一直存在,但是一般是拖拽时才会触发,用户也能理解这个逻辑
但是目前这个组件销毁时就触发一次自动触发计算会给用户造成一种bug的错觉
解决方法
我们的本意是为了防止
mousemove
和mouseup
没有及时被移除,如下面所示,在触发handleMouseDown
时,会注册监听,在handleMouseUp
时,会解除监听因此这里增加
if(this.isStartDragging)
的判断,isStartDragging=true
代表没有触发handleMouseUp()
,此时监听还没被移除;在拖拽情况下(isStartDragging=true),在组件突然销毁时,强制触发cancelDrag()
进行监听事件的移除