aminghadersohi commented on code in PR #44878:
URL: https://github.com/apache/superset/pull/44878#discussion_r4412091117
##########
superset-frontend/src/explore/components/controls/TextControl/index.tsx:
##########
@@ -95,26 +107,61 @@ function TextControl<T extends InputValueType =
InputValueType>({
[isFloat, isInt, onChange],
);
- const debouncedOnChangeRef = useRef(
- debounce((inputValue: string, changeFn: (val: string) => void) => {
- changeFn(inputValue);
+ // 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;
+
+ // Outbound onChange keeps a trailing coalescing window so consumers
+ // (renderTrigger re-renders, filtered collection tables) only see the
+ // settled value rather than every intermediate keystroke the deferred value
+ // happens to commit.
+ // Newest raw keystroke, not yet emitted. Blur emits this rather than the
+ // (possibly lagging) deferred value so the last character is never lost.
+ const latestTypedRef = useRef<string | null>(null);
+ const debouncedEmitRef = useRef(
+ debounce((inputValue: string) => {
+ if (latestTypedRef.current === inputValue) {
Review Comment:
With an edit queued, blurring after an external reset but before the
deferred null commits flushes the stale edit and overwrites the reset. Skip the
callback when `latestTypedRef` is null.
```suggestion
// An external reset clears latestTypedRef; drop a stale queued emit.
if (latestTypedRef.current === null) {
return;
}
if (latestTypedRef.current === inputValue) {
```
--
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]