Skip to content

fix echarts this.mouse - #8041

Merged
philippjfr merged 1 commit into
mainfrom
enhancement/fix-echarts-this-mouse
Jul 11, 2025
Merged

fix echarts this.mouse#8041
philippjfr merged 1 commit into
mainfrom
enhancement/fix-echarts-this-mouse

Conversation

@MarcSkovMadsen

@MarcSkovMadsen MarcSkovMadsen commented Jul 11, 2025

Copy link
Copy Markdown
Collaborator

Closing #7889

I don't fully understand the fix from GPT 4.1. But its simple and the Echarts events works for me in both edge and firefox after the change.

echarts-this.mouse-firefox.mp4

GPT 4.1 explanation

The error described in #fetch (TypeError: this.mouse is not a function at Object.pointer) occurs when handling mouse events like mouseover in ECharts, specifically in Edge (but not Firefox).

Looking at echarts.ts, mouse events are handled by the EChartsView._subscribe() method. For each event in event_config, it attaches a callback that serializes the event using serializeEvent:

The error trace points to a problem inside serializeEvent, specifically when it tries to call this.mouse. In event-to-object.ts, there is a class EventTransformCategories with a mouse method, but the context (this) may be lost if the method is called incorrectly (e.g., as a plain function instead of a method).

Root cause:
If EventTransformCategories.mouse is called without binding to an instance, this is undefined, so this.mouse fails. This can happen if the code does something like elementTransformCategoriescategorycategory instead of elementTransformCategories.mouse.call(instance, event).

Why Edge but not Firefox?
Edge may be stricter about this binding in certain contexts, or the event object structure may differ, triggering the bug only in Edge.

How to fix:
Ensure that all methods in EventTransformCategories are called with the correct this context, e.g., by using .call(instance, event) or converting them to static methods if they don't rely on instance state.

Summary:
The bug is caused by incorrect method binding in the event serialization logic, leading to this.mouse is not a function when handling mouse events in Edge. Fix the binding in serializeEvent to resolve the issue.

EChartsView
serializeEvent
EventTransformCategories
Similar code found with 1 license type - V

@codecov

codecov Bot commented Jul 11, 2025

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 86.11%. Comparing base (edb382d) to head (01be6a7).
Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8041      +/-   ##
==========================================
- Coverage   87.08%   86.11%   -0.97%     
==========================================
  Files         346      346              
  Lines       53717    53717              
==========================================
- Hits        46780    46259     -521     
- Misses       6937     7458     +521     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@philippjfr philippjfr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why this is needed tbh but if it works, it works.

@philippjfr
philippjfr enabled auto-merge (squash) July 11, 2025 07:26
@philippjfr
philippjfr disabled auto-merge July 11, 2025 08:26
@philippjfr
philippjfr merged commit 9cc11af into main Jul 11, 2025
29 of 35 checks passed
@philippjfr
philippjfr deleted the enhancement/fix-echarts-this-mouse branch July 11, 2025 08:26
philippjfr pushed a commit that referenced this pull request Jul 11, 2025
@github-actions

Copy link
Copy Markdown

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Oct 21, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants