codeant-ai-for-open-source[bot] commented on code in PR #39068:
URL: https://github.com/apache/superset/pull/39068#discussion_r3591350337
##########
superset-frontend/packages/superset-ui-core/src/components/Select/AsyncSelect.tsx:
##########
@@ -270,6 +280,8 @@ const AsyncSelect = forwardRef(
}
return previousState;
});
+ setInputValue('');
+ setSelectOptions(prev => prev.sort(sortComparatorForNoSearch));
Review Comment:
**Suggestion:** This mutates React state in place because `Array.sort` edits
the existing array and returns the same reference. In-place mutation can cause
missed updates and stale memoized computations; sort a copied array before
setting state so React receives a new immutable value. [logic error]
<details>
<summary><b>Severity Level:</b> Major ⚠️</summary>
```mdx
⚠️ AsyncSelect option ordering may not update reliably.
⚠️ Memoized computations depending on selectOptions can become stale.
⚠️ Group user picker may show unsorted or inconsistent options.
⚠️ UploadDataModel AsyncSelects inherit this mutable state pattern.
```
</details>
<details>
<summary><b>Steps of Reproduction ✅ </b></summary>
```mdx
1. Open the Groups modal, which uses AsyncSelect in multi-select mode for
the Users field
(`superset-frontend/src/features/groups/GroupListModal.tsx:147-151` shows
the <AsyncSelect
mode="multiple" /> usage).
2. Trigger a user selection so that AsyncSelect's `handleOnSelect`
multi-select branch
runs
(`superset-frontend/packages/superset-ui-core/src/components/Select/AsyncSelect.tsx:19-55`
from the BulkRead output, where `isSingleMode` is false and it enters the
`else` block).
3. In that branch, React state `selectOptions` is updated via
`setSelectOptions(prev =>
prev.sort(sortComparatorForNoSearch));` at line 284 (`AsyncSelect.tsx:284`),
which mutates
the existing `prev` array in place and returns the same reference.
4. Because React compares the old and new state by reference, this in-place
mutation can
cause missed re-renders or stale memoized computations when
`setSelectOptions` is called
without another state change (for example, any future refactor or call site
that sorts
options without changing `selectValue` or `inputValue`), violating React’s
immutable state
expectations and making option ordering updates unreliable.
```
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=b4b6b0ea08b040398ec9ea1975cc3daf&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=b4b6b0ea08b040398ec9ea1975cc3daf&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
*(Use Cmd/Ctrl + Click for best experience)*
<details>
<summary><b>Prompt for AI Agent 🤖 </b></summary>
```mdx
This is a comment left during a code review.
**Path:**
superset-frontend/packages/superset-ui-core/src/components/Select/AsyncSelect.tsx
**Line:** 284:284
**Comment:**
*Logic Error: This mutates React state in place because `Array.sort`
edits the existing array and returns the same reference. In-place mutation can
cause missed updates and stale memoized computations; sort a copied array
before setting state so React receives a new immutable 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%2F39068&comment_hash=d2202a993117e5480f8c48eba9fe284217e6e7d75b96904e8b96d40585cd3259&reaction=like'>👍</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F39068&comment_hash=d2202a993117e5480f8c48eba9fe284217e6e7d75b96904e8b96d40585cd3259&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]