bito-code-review[bot] commented on PR #43220:
URL: https://github.com/apache/superset/pull/43220#issuecomment-5302364462
<!-- Bito Reply -->
The flagged issue is correct. The race condition occurs because the
component maintains a `localValue` state that can become desynchronized from
the external `value` prop when an update is pending in the debounced callback.
To resolve this, you should clear the pending debounced callback whenever
the external `value` prop changes. You can achieve this by using a `useRef` to
store the debounced function and calling `.cancel()` on it when the `value`
prop changes, ensuring that any queued `handleChange` calls are discarded
before the state is updated to the new external value.
**superset-frontend/src/explore/components/controls/TextControl/index.tsx**
```
// Inside TextControl component
const debouncedOnChangeRef = useRef<ReturnType<typeof debounce>>();
// When value changes, cancel pending debounced calls
useEffect(() => {
debouncedOnChangeRef.current?.cancel();
}, [value]);
```
--
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]