rahul37wallst-sudo opened a new pull request, #21705:
URL: https://github.com/apache/echarts/pull/21705
## Brief Information
This pull request is in the type of:
- [x] 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
- #21584: Event handlers filtered by `seriesId` could incorrectly run for
another series after a preceding handler called `setOption`.
## 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:
```js
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.
- [x] 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
- [x] Please squash the commits into a single one when merging.
### Other information
Validated with:
```sh
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.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]