Skip to content

fix(core): preserve event query context. close #21584#21705

Open
rahul37wallst-sudo wants to merge 1 commit into
apache:masterfrom
rahul37wallst-sudo:fix-21584-event-query-context
Open

fix(core): preserve event query context. close #21584#21705
rahul37wallst-sudo wants to merge 1 commit into
apache:masterfrom
rahul37wallst-sudo:fix-21584-event-query-context

Conversation

@rahul37wallst-sudo

Copy link
Copy Markdown

Brief Information

This pull request is in the type of:

  • bug fixing
  • new feature
  • others

What does this PR do?

Preserves mouse-event query context across nested ECharts events so handlers remain correctly filtered when an earlier handler calls setOption.

Fixed issues

Details

Before: What was the problem?

Mouse-event queries use ECEventProcessor.eventInfo to determine the source series or component.

When a matching handler synchronously called setOption, ECharts emitted a nested updated event. The nested event's afterTrigger hook cleared the shared mouse-event context before the original click dispatch had finished.

Consequently, later click handlers found no event context. Since missing context is treated as unfiltered, a handler registered for another series could run incorrectly:

chart.on('click', { seriesId: 'first' }, function () {
    chart.setOption(...);
});

chart.on('click', { seriesId: 'second' }, function () {
    // This could incorrectly run after clicking "first".
});

After: How does it behave after the fixing?

The mouse-event handler now scopes eventInfo to its dispatch:

  1. Save the previous event context.
  2. Set the current mouse-event context.
  3. Trigger the event handlers.
  4. Restore the previous context in a finally block.

The unconditional afterTrigger cleanup was removed because it could clear an outer event's context during a nested trigger.

As a result, synchronous nested events no longer bypass the remaining event-query filters. The context is also restored safely if an event handler throws.

A regression test verifies that:

  • clicking the first series only invokes its matching handler, even when that handler calls setOption;
  • a later click on the second series is still routed to the correct handler.

Document Info

One of the following should be checked.

  • This PR doesn't relate to document changes
  • The document should be updated later
  • The document changes have been made in apache/echarts-doc#xxx

Misc

Security Checking

  • This PR uses security-sensitive Web APIs.

ZRender Changes

  • This PR depends on ZRender changes (ecomfe/zrender#xxx).

Related test cases or examples to use the new APIs

  • test/ut/spec/api/event.test.ts

Merging options

  • Please squash the commits into a single one when merging.

Other information

Validated with:

npx jest --config test/ut/jest.config.cjs --coverage=false --runInBand --runTestsByPath test/ut/spec/api/event.test.ts
TZ=UTC npm test -- --runInBand
npm run checktype
npm run lint
npx eslint src/core/echarts.ts src/util/ECEventProcessor.ts test/ut/spec/api/event.test.ts
git diff --check

The complete unit suite passed with 26 test suites and 193 tests.

@echarts-bot

echarts-bot Bot commented Jul 22, 2026

Copy link
Copy Markdown

Thanks for your contribution!
The community will review it ASAP. In the meanwhile, please checkout the coding standard and Wiki about How to make a pull request.

Please DO NOT commit the files in dist, i18n, and ssr/client/dist folders in a non-release pull request. These folders are for release use only.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant