fix(Handler): allow click through when elements are recreated between mousedown and mouseup - #1165
Open
waterWang wants to merge 1 commit into
Open
Conversation
… mousedown and mouseup When setOption is called at high frequency (>=30fps) between mousedown and mouseup, zrender elements are recreated. The click handler compares element references (_downEl !== _upEl), which always fails for recreated elements, causing click events (e.g. legend toggle) to never fire. Use the existing __zr check pattern (already used in mousemove handler) to detect when _downEl was removed from zrender. If the element was removed (recreated), allow the click to proceed to the new element. Fixes apache/echarts#21566
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
When
setOptionis called at high frequency (>=30fps, e.g. real-time WebSocket data) betweenmousedownandmouseup, zrender elements are recreated. Theclickhandler compares element references (_downEl !== _upEl), which always fails for recreated elements, causing click events (e.g. legend toggle) to never fire.This bug is reported as apache/echarts#21566.
Root Cause
In
Handler.ts, theclickhandler checks:When
setOptionis called betweenmousedownandmouseup, the display list is updated and elements are recreated. The_downElreference (stored duringmousedown) points to the old, removed element, while_upEl(set duringmouseup) points to the new element. The reference comparison always fails, cancelling all click events.Fix
Use the existing
__zrcheck pattern (already used in themousemovehandler at line ~424) to detect when_downElwas removed from zrender due to element recreation. If the element was removed (i.e.,_downEl.__zris falsy), allow the click to proceed to the new element at the same position.The
mousemovehandler already uses this pattern:Testing
setOptionis called at 60fpsmousemovedistance check (> 4px) still applies