rusackas commented on code in PR #44878:
URL: https://github.com/apache/superset/pull/44878#discussion_r4406474535


##########
superset-frontend/src/explore/components/controls/TextControl/index.tsx:
##########
@@ -95,26 +106,28 @@ function TextControl<T extends InputValueType = 
InputValueType>({
     [isFloat, isInt, onChange],
   );
 
-  const debouncedOnChangeRef = useRef(
-    debounce((inputValue: string, changeFn: (val: string) => void) => {
-      changeFn(inputValue);
-    }, Constants.FAST_DEBOUNCE),
-  );
+  // Read through a ref so a parent re-render that hands down a new `onChange`
+  // identity doesn't re-fire this effect on its own -- only an actual
+  // keystroke (a change to `deferredPendingValue`) should.
+  const handleChangeRef = useRef(handleChange);
+  handleChangeRef.current = handleChange;
 
-  useEffect(
-    () => () => {
-      debouncedOnChangeRef.current.cancel();
-    },
-    [],
-  );
+  // Fires once the deferred value catches up with the latest keystroke.
+  // Low-priority and interrupted by each new keystroke, unlike a fixed-delay
+  // debounce, so the input never lags behind a burst of typing.
+  useEffect(() => {

Review Comment:
   Good catch, @sadpandajoe. Outbound `onChange` now goes through a trailing 
`FAST_DEBOUNCE` window again, so `120` and `1e-12` emit once with the settled 
value. The deferred value still gates the update.



##########
superset-frontend/src/explore/components/controls/TextControl/index.tsx:
##########
@@ -95,26 +106,28 @@ function TextControl<T extends InputValueType = 
InputValueType>({
     [isFloat, isInt, onChange],
   );
 
-  const debouncedOnChangeRef = useRef(
-    debounce((inputValue: string, changeFn: (val: string) => void) => {
-      changeFn(inputValue);
-    }, Constants.FAST_DEBOUNCE),
-  );
+  // Read through a ref so a parent re-render that hands down a new `onChange`
+  // identity doesn't re-fire this effect on its own -- only an actual
+  // keystroke (a change to `deferredPendingValue`) should.
+  const handleChangeRef = useRef(handleChange);
+  handleChangeRef.current = handleChange;
 
-  useEffect(
-    () => () => {
-      debouncedOnChangeRef.current.cancel();
-    },
-    [],
-  );
+  // Fires once the deferred value catches up with the latest keystroke.
+  // Low-priority and interrupted by each new keystroke, unlike a fixed-delay
+  // debounce, so the input never lags behind a burst of typing.
+  useEffect(() => {
+    if (deferredPendingValue !== null) {
+      handleChangeRef.current(deferredPendingValue);

Review Comment:
   Fixed in 3749a82. Same trailing window on `onChange`, plus a flush on blur, 
so the Metrics tab filter only sees the settled label.



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