Skip to content

fix(Handler): allow click through when elements are recreated between mousedown and mouseup - #1165

Open
waterWang wants to merge 1 commit into
ecomfe:masterfrom
waterWang:fix/click-detection-recreated-elements
Open

fix(Handler): allow click through when elements are recreated between mousedown and mouseup#1165
waterWang wants to merge 1 commit into
ecomfe:masterfrom
waterWang:fix/click-detection-recreated-elements

Conversation

@waterWang

Copy link
Copy Markdown

Summary

When setOption is called at high frequency (>=30fps, e.g. real-time WebSocket data) 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.

This bug is reported as apache/echarts#21566.

Root Cause

In Handler.ts, the click handler checks:

if (this._downEl !== this._upEl) { return; }

When setOption is called between mousedown and mouseup, the display list is updated and elements are recreated. The _downEl reference (stored during mousedown) points to the old, removed element, while _upEl (set during mouseup) points to the new element. The reference comparison always fails, cancelling all click events.

Fix

Use the existing __zr check pattern (already used in the mousemove handler at line ~424) to detect when _downEl was removed from zrender due to element recreation. If the element was removed (i.e., _downEl.__zr is falsy), allow the click to proceed to the new element at the same position.

The mousemove handler already uses this pattern:

if (lastHoveredTarget && !lastHoveredTarget.__zr) {
    lastHovered = this.findHover(lastHovered.x, lastHovered.y);
}

Testing

  • Clicking legend items works correctly when setOption is called at 60fps
  • Dragging (pan/zoom) is unaffected — the mousemove distance check (> 4px) still applies
  • Normal click behavior is preserved when elements are not recreated

… 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant