codeant-ai-for-open-source[bot] commented on code in PR #41074:
URL: https://github.com/apache/superset/pull/41074#discussion_r3482921432


##########
superset-frontend/packages/superset-ui-core/src/components/Select/AsyncSelect.tsx:
##########
@@ -267,6 +267,9 @@ const AsyncSelect = forwardRef(
         });
         fireOnChange();
       }
+      if (autoClearSearchValue) {
+        setInputValue('');
+      }

Review Comment:
   **Suggestion:** Clearing `inputValue` on select without handling 
`fetchOnlyOnSearch` creates inconsistent async behavior: when 
`fetchOnlyOnSearch` is true, `allowFetch` becomes false after this clear, so 
the reset/fetch effect is skipped and the dropdown keeps showing stale search 
results while the visible query is empty. This makes the UI state inconsistent 
and can surface outdated options after selection. Only clear in this path if 
you also explicitly reset options/state for `fetchOnlyOnSearch` mode. 
[incorrect condition logic]
   
   <details>
   <summary><b>Severity Level:</b> Major ⚠️</summary>
   
   ```mdx
   - ⚠️ AsynchronousSelect story shows stale results after clearing search.
   - ⚠️ Future fetchOnlyOnSearch AsyncSelect users see inconsistent dropdown 
state.
   - ⚠️ Remote multi-select UX degrades for large async option sets.
   ```
   </details>
   <details>
   <summary><b>Steps of Reproduction ✅ </b></summary>
   
   ```mdx
   1. Open the Storybook story `AsynchronousSelect` defined in
   
`superset-frontend/packages/superset-ui-core/src/components/Select/AsyncSelect.stories.tsx:11-21`,
   configure its controls so that `fetchOnlyOnSearch` is `true` (passed through 
to
   `<AsyncSelect>` at line 101) and `mode="multiple"` (so the 
multiple-selection path in
   `handleOnSelect` is used).
   
   2. With the story rendered, open the dropdown; in `AsyncSelect`
   
(`superset-frontend/packages/superset-ui-core/src/components/Select/AsyncSelect.tsx`),
   `allowFetch` is computed at line 171 as `!fetchOnlyOnSearch || inputValue`, 
which is
   `false` because `fetchOnlyOnSearch` is true and `inputValue` is initially 
empty, so the
   fetch/reset effect at lines 90-110 (which restores base options or refetches 
on empty
   input) is gated off until a non-empty search term is entered.
   
   3. Type a search term such as `"geo"` into the combobox; `handleOnSearch` at 
lines 440-468
   sets `inputValue` to the typed string and, with `allowFetch` now true, 
triggers
   `debouncedFetchPage`, which calls `fetchPage` at lines 333-423 to populate 
`selectOptions`
   with remote results (e.g. the user `"George"`), which are rendered by 
`<StyledSelect>` via
   its `options={fullSelectOptions}` prop at lines 225-226.
   
   4. Click one of the search results to select it; `handleOnSelect` at lines 
243-274 runs,
   and in multiple mode it appends the selected item to `selectValue` (lines 
255-268), then
   executes the new block `if (autoClearSearchValue) { setInputValue(''); }` at 
lines
   270-272, which clears `inputValue` while leaving `selectOptions` unchanged; 
because
   `fetchOnlyOnSearch` is true, `allowFetch` recomputes to `false` (line 171), 
so on the
   subsequent effect run the guarded block at lines 90-110 is skipped and no 
reset or refetch
   occurs, resulting in the dropdown still showing the stale filtered search 
results even
   though the visible search input (controlled by `autoClearSearchValue` on 
`<StyledSelect>`
   at line 204) is now empty.
   ```
   </details>
   
   [![Fix in 
Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=73997958fe44420c8f0685c068dd76c7&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 [![Fix in VSCode 
Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=73997958fe44420c8f0685c068dd76c7&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:** 270:272
   **Comment:**
        *Incorrect Condition Logic: Clearing `inputValue` on select without 
handling `fetchOnlyOnSearch` creates inconsistent async behavior: when 
`fetchOnlyOnSearch` is true, `allowFetch` becomes false after this clear, so 
the reset/fetch effect is skipped and the dropdown keeps showing stale search 
results while the visible query is empty. This makes the UI state inconsistent 
and can surface outdated options after selection. Only clear in this path if 
you also explicitly reset options/state for `fetchOnlyOnSearch` mode.
   
   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%2F41074&comment_hash=44fffee9321c496a0bc1000f6530389ccb30a51d61734676eb3b8a957a68dc40&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41074&comment_hash=44fffee9321c496a0bc1000f6530389ccb30a51d61734676eb3b8a957a68dc40&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]

Reply via email to