codeant-ai-for-open-source[bot] commented on code in PR #41111:
URL: https://github.com/apache/superset/pull/41111#discussion_r3450239729
##########
superset-frontend/plugins/plugin-chart-echarts/src/components/Echart.tsx:
##########
@@ -201,6 +208,14 @@ function Echart(
chartRef.current?.on(name, handler);
});
+ previousQueryEventHandlers.current.forEach(({ name, handler }) => {
+ chartRef.current?.off(name, handler);
+ });
+ (queryEventHandlers || []).forEach(({ name, query, handler }) => {
+ chartRef.current?.on(name, query, handler);
+ });
+ previousQueryEventHandlers.current = queryEventHandlers || [];
Review Comment:
**Suggestion:** Query listeners are removed after regular listeners are
rebound, which can accidentally unregister the newly rebound regular listener
when both registrations reuse the same callback function. Remove stale query
listeners before rebinding regular listeners (or use distinct wrapped
callbacks) so `off(name, handler)` does not clear the active non-query
listener. [logic error]
<details>
<summary><b>Severity Level:</b> Major ⚠️</summary>
```mdx
- ❌ Shared click handler can be silently unregistered after rerender.
- ⚠️ Cross-filter click interactions may stop working unexpectedly.
- ⚠️ Future charts reusing callbacks risk broken event handling.
```
</details>
<details>
<summary><b>Steps of Reproduction ✅ </b></summary>
```mdx
1. Note that the Echart wrapper binds regular and query-based listeners in
the same effect
in
`superset-frontend/plugins/plugin-chart-echarts/src/components/Echart.tsx`
around lines
205–217: regular handlers use `chartRef.current?.off(name);
chartRef.current?.on(name,
handler);` and query handlers are torn down with
`chartRef.current?.off(name, handler);`
and rebound with `chartRef.current?.on(name, query, handler);`, while
previous query
handlers are tracked in `previousQueryEventHandlers.current`.
2. Observe in
`superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/EchartsTimeseries.tsx`
lines 220–103 that the chart passes both `eventHandlers` and
`queryEventHandlers` into
`<Echart />` (lines 54–70 of the same file), demonstrating real usage of
both mechanisms,
even though the current implementation uses different callbacks for each.
3. Using the existing test harness in
`superset-frontend/plugins/plugin-chart-echarts/src/components/Echart.test.tsx`
lines 6–12
(`renderEchart` and `trigger` helpers), write a test similar to
`test('replaces stale
query event handlers without clearing regular event handlers', ...)` at
lines 25–104, but
set both `eventHandlers.click` and `queryEventHandlers[0].handler` to the
same function
reference (e.g., `const sharedHandler = jest.fn();` and pass `sharedHandler`
in both
places), then `render(renderEchart({ eventHandlers: { click: sharedHandler },
queryEventHandlers: [{ name: 'click', query: 'xAxis.category', handler:
sharedHandler }]
}))`.
4. In that test, call `rerender(renderEchart({ eventHandlers: { click:
sharedHandler },
queryEventHandlers: [] }))` to trigger the `useEffect` in `Echart.tsx`, then
invoke
`trigger('click')` (defined at line 10 in `Echart.test.tsx`); you will see
that
`sharedHandler` is not called because the effect first rebinds the regular
listener with
`off(name); on(name, handler)` and then executes
`previousQueryEventHandlers.current.forEach(({ name, handler }) =>
chartRef.current?.off(name, handler));`, where `off(name, handler)` (ECharts
API)
unregisters any listener for that event and handler, including the newly
rebound regular
listener, leaving no active handler for that click event.
```
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=b25797e9971c43be8c296eb9afe51a7a&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
[](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=b25797e9971c43be8c296eb9afe51a7a&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
*(Use Cmd/Ctrl + Click for best experience)*
<details>
<summary><b>Prompt for AI Agent 🤖 </b></summary>
```mdx
This is a comment left during a code review.
**Path:**
superset-frontend/plugins/plugin-chart-echarts/src/components/Echart.tsx
**Line:** 211:217
**Comment:**
*Logic Error: Query listeners are removed after regular listeners are
rebound, which can accidentally unregister the newly rebound regular listener
when both registrations reuse the same callback function. Remove stale query
listeners before rebinding regular listeners (or use distinct wrapped
callbacks) so `off(name, handler)` does not clear the active non-query listener.
Validate the correctness of the flagged issue. If correct, How can I resolve
this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask
user if the user wants to fix the rest of the comments as well. if said yes,
then fetch all the comments validate the correctness and implement a minimal fix
```
</details>
<a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41111&comment_hash=3363cd17e6fcfbd21bf4166283e04bbc23af4f90251c113386be22cbdfb3248e&reaction=like'>👍</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41111&comment_hash=3363cd17e6fcfbd21bf4166283e04bbc23af4f90251c113386be22cbdfb3248e&reaction=dislike'>👎</a>
--
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]