endimonan commented on code in PR #38470:
URL: https://github.com/apache/superset/pull/38470#discussion_r2935296399


##########
superset-frontend/src/filters/components/Select/SelectFilterPlugin.tsx:
##########
@@ -483,6 +506,47 @@ export default function PluginFilterSelect(props: 
PluginFilterSelectProps) {
     setExcludeFilterValues(value === 'true');
   };
 
+  const debouncedLikeChange = useMemo(
+    () =>
+      debounce((text: string) => {
+        if (text) {
+          updateDataMask([text]);
+        } else {
+          updateDataMask(null);
+        }
+      }, Constants.SLOW_DEBOUNCE),
+    [updateDataMask],
+  );
+
+  useEffect(() => {
+    if (!isLikeOperator || clearAllTrigger) {
+      debouncedLikeChange.cancel();
+    }
+  }, [clearAllTrigger, debouncedLikeChange, isLikeOperator]);
+
+  useEffect(() => () => debouncedLikeChange.cancel(), [debouncedLikeChange]);

Review Comment:
   This is a valid edge case, but the suggested ref-based cleanup is not safe 
as written. It stops canceling previously created debounced instances when 
debouncedLikeChange is recreated, which can reintroduce stale updates.
   
   I fixed this by keeping a single stable debounced function and reading the 
latest updateDataMask from a ref. That preserves pending LIKE input across 
rerenders while still canceling correctly on clear-all, operator transitions, 
and unmount. I also added a test covering the rerender-before-debounce case.



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