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


##########
superset-frontend/src/explore/components/controls/ColumnConfigControl/ControlForm/index.tsx:
##########
@@ -70,13 +72,27 @@ export default function ControlForm({
   children,
 }: ControlFormProps) {
   const theme = useTheme();
+  const latestValue = useRef<JsonObject>(value ?? {});
+  const latestOnChange = useRef(onChange);
   const debouncedOnChange = useMemo(
-    () =>
-      ({
-        0: onChange,
-        [Constants.FAST_DEBOUNCE]: debounce(onChange, Constants.FAST_DEBOUNCE),
-      }) as Record<number, typeof onChange>,
-    [onChange],
+    () => ({}) as Record<number, DebouncedFunc<() => void>>,
+    [],
+  );
+
+  useEffect(() => {
+    latestOnChange.current = onChange;
+  }, [onChange]);
+
+  useEffect(() => {
+    latestValue.current = value ?? {};
+    Object.values(debouncedOnChange).forEach(callback => callback.cancel());
+  }, [value, debouncedOnChange]);
+
+  useEffect(
+    () => () => {
+      Object.values(debouncedOnChange).forEach(callback => callback.cancel());

Review Comment:
   <div>
   
   
   <div id="suggestion">
   <div id="issue"><b>Duplicated cancel-all logic</b></div>
   <div id="fix">
   
   The cancel-all logic `Object.values(debouncedOnChange).forEach(callback => 
callback.cancel())` now appears three times: in the `value` sync effect, the 
unmount cleanup, and the `debounceDelay === 0` branch. Extract one 
`cancelAllPending` helper so a future scheduling site cannot forget a cancel 
and silently leak a pending edit.
   </div>
   
   
   </div>
   
   
   
   
   <small><i>Code Review Run #d94eef</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]

Reply via email to