bito-code-review[bot] commented on code in PR #44810:
URL: https://github.com/apache/superset/pull/44810#discussion_r4139882946
##########
superset-frontend/plugins/plugin-chart-echarts/src/components/Echart.tsx:
##########
@@ -289,12 +290,59 @@ function Echart(
const notMerge = !isDashboardRefreshing;
chartRef.current?.dispatchAction({ type: 'hideTip' });
+ // setOption(notMerge:true) replaces the dataZoom config, dropping any
+ // range the user has engaged. Preserve it across the call.
+ const previousZoom = notMerge
+ ? (
+ chartRef.current?.getOption() as {
+ dataZoom?: DataZoomComponentOption[];
+ }
+ )?.dataZoom
+ : undefined;
chartRef.current?.setOption(themedEchartOptions, {
notMerge,
replaceMerge: notMerge ? undefined : ['series'],
// lazyUpdate defers render, causing tooltip crashes on stale shapes
(#39247)
lazyUpdate: false,
});
+ if (previousZoom?.length) {
+ // Skip restore when the new option reshapes dataZoom (different count
+ // means index-based restore could land on the wrong component).
+ const newZoom = (
+ chartRef.current?.getOption() as {
+ dataZoom?: DataZoomComponentOption[];
+ }
+ )?.dataZoom;
+ if (newZoom?.length === previousZoom.length) {
+ const batch = previousZoom
+ .map((dz, dataZoomIndex) => ({
+ dataZoomIndex,
+ start: dz.start,
+ end: dz.end,
+ startValue: dz.startValue,
+ endValue: dz.endValue,
+ }))
+ .filter(b => {
+ const hasAny =
+ b.start !== undefined ||
+ b.end !== undefined ||
+ b.startValue !== undefined ||
+ b.endValue !== undefined;
+ if (!hasAny) return false;
+ // Default full-range zoom is functionally identical to the
+ // fresh state setOption already produces — skip the dispatch.
+ const isDefaultRange =
+ b.start === 0 &&
+ b.end === 100 &&
+ b.startValue === undefined &&
+ b.endValue === undefined;
+ return !isDefaultRange;
+ });
Review Comment:
<div>
<div id="suggestion">
<div id="issue"><b>Stale zoom overrides new config</b></div>
<div id="fix">
The same-count guard doesn't catch same-count config changes: if
`echartOptions` arrives with a deliberately different `dataZoom` range (e.g. an
explore control edit), the stale interactive range in `previousZoom` silently
overrides it. Consider skipping the restore when `newZoom` already reflects an
intentional range, or tracking user-initiated zoom via `datazoom` events; this
also avoids redundant `dispatchAction` event side effects.
</div>
</div>
<small><i>Code Review Run #7ebc2e</i></small>
</div>
---
Should Bito avoid suggestions like this for future reviews? (<a
href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
- [ ] Yes, avoid them
--
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]