bito-code-review[bot] commented on code in PR #44810:
URL: https://github.com/apache/superset/pull/44810#discussion_r4139942958


##########
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:
   <!-- Bito Reply -->
   The reviewer's suggestion highlights a potential edge case where the 
`previousZoom` state might override an intentional `dataZoom` range provided in 
new `echartOptions`. While the current implementation correctly restores 
user-dragged ranges, it does not distinguish between a default state and an 
intentional configuration change. Addressing this by checking if `newZoom` 
reflects an intentional range or tracking user-initiated zoom events would 
improve robustness and prevent unintended side effects.
   
   **superset-frontend/plugins/plugin-chart-echarts/src/components/Echart.tsx**
   ```
   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;
   ```



-- 
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]

Reply via email to