codeant-ai-for-open-source[bot] commented on code in PR #43220:
URL: https://github.com/apache/superset/pull/43220#discussion_r3789415002
##########
superset-frontend/src/explore/components/controls/TextControl/index.tsx:
##########
@@ -117,12 +117,16 @@ function TextControl<T extends InputValueType =
InputValueType>({
[handleChange],
);
- // Sync local value when prop value changes externally
- let displayValue = localValue;
- if (safeStringify(prevValueRef.current) !== safeStringify(value)) {
- prevValueRef.current = value;
- displayValue = safeStringify(value);
+ // Sync local value when prop value changes externally. Adjusting state
during
+ // render is React's documented pattern for this; deriving a display value
+ // without writing it back left `localValue` holding the superseded text, so
+ // the very next render -- one that only changes an unrelated prop, and so
+ // does not re-enter this branch -- put the stale value back in the input.
+ if (safeStringify(prevValue) !== safeStringify(value)) {
+ setPrevValue(value);
+ setLocalValue(safeStringify(value));
}
Review Comment:
**Suggestion:** When an external `value` change is detected, this updates
the displayed state but leaves any pending `debouncedOnChangeRef` callback
active. If the user edited the field immediately before the external reset or
undo, the queued callback still invokes `handleChange` with the superseded text
and can overwrite the external value in the parent. Cancel the pending debounce
or invalidate queued edits when synchronizing an external value. [race
condition]
<details>
<summary><b>Severity Level:</b> Major ⚠️</summary>
```mdx
- ❌ External undo or reset can be overwritten by stale input.
- ⚠️ Affected controls use parent-managed values and debounced changes.
- ⚠️ User-visible form state can revert after synchronization.
```
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=01258eefffb941c3b717c24c9713b8e7&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
[](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=01258eefffb941c3b717c24c9713b8e7&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
<details>
<summary><b>Prompt for AI Agent 🤖 </b></summary>
```mdx
This is a comment left during a code review.
**Path:**
superset-frontend/src/explore/components/controls/TextControl/index.tsx
**Line:** 125:128
**Comment:**
*Race Condition: When an external `value` change is detected, this
updates the displayed state but leaves any pending `debouncedOnChangeRef`
callback active. If the user edited the field immediately before the external
reset or undo, the queued callback still invokes `handleChange` with the
superseded text and can overwrite the external value in the parent. Cancel the
pending debounce or invalidate queued edits when synchronizing an external
value.
Validate the correctness of the flagged issue. If correct, How can I resolve
this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask
user if the user wants to fix the rest of the comments as well. if said yes,
then fetch all the comments validate the correctness and implement a minimal fix
```
</details>
<a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F43220&comment_hash=aeb6e170839b41ef9ba22044f2abf25b99a642e075160e168e8c11f4a1ec513a&reaction=like'>👍</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F43220&comment_hash=aeb6e170839b41ef9ba22044f2abf25b99a642e075160e168e8c11f4a1ec513a&reaction=dislike'>👎</a>
--
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]