codeant-ai-for-open-source[bot] commented on code in PR #39068:
URL: https://github.com/apache/superset/pull/39068#discussion_r3611134545
##########
superset-frontend/packages/superset-ui-core/src/components/Select/Select.tsx:
##########
@@ -366,6 +387,42 @@ const Select = forwardRef(
onSelect?.(selectedItem, option);
};
+ // The underlying Select silently drops tokens it cannot match against the
+ // rendered options. That happens whenever tokenization outpaces the
+ // debounced option registration, e.g. dead-key keyboard layouts deliver a
+ // closing quote and a separator in a single input event.
+ reconcileTokensRef.current = (tokens: string[]) => {
+ if (isSingleMode || !allowNewOptions) {
+ return;
+ }
+ setTimeout(() => {
+ tokens.forEach(token => {
+ const matched = getOption(token, fullSelectOptionsRef.current, true);
+ const matchedValue = isObject(matched) ? matched.value : matched;
+ if (hasOption(matchedValue ?? token, selectValueRef.current)) {
+ return;
+ }
+ const option = isObject(matched)
+ ? (matched as AntdLabeledValue)
+ : { label: token, value: token, isNewOption: true };
+ if (!matched) {
+ const addOption = (previous: SelectOptionsType) =>
+ hasOption(token, previous, true)
+ ? previous
+ : [option, ...previous];
+ setSelectOptions(addOption);
+ setVisibleOptions(addOption);
+ }
+ handleOnSelect(
+ (labelInValue
+ ? { label: option.label, value: option.value }
+ : option.value) as string | AntdLabeledValue,
+ option as AntdLabeledValue,
+ );
+ });
+ });
Review Comment:
**Suggestion:** The deferred token reconciliation runs in a `setTimeout`, so
it can execute after newer user actions (like clear/deselect or additional
typing) and re-apply stale tokens out of order. This creates a race where old
input can be selected after the UI has moved on; guard the callback with a
freshness check or cancel prior scheduled reconciliations before scheduling a
new one. [race condition]
<details>
<summary><b>Severity Level:</b> Major ⚠️</summary>
```mdx
- ⚠️ Multi-select inputs may resurrect cleared filter chips unexpectedly.
- ⚠️ Native filters can apply tokens user already removed.
```
</details>
<details>
<summary><b>Steps of Reproduction ✅ </b></summary>
```mdx
1. Open the Select component implemented in `Select.tsx:185-213` in a screen
that uses it
in multi-select mode (isSingleMode is false) with `allowNewOptions` enabled
so the
reconciliation logic at `Select.tsx:394-424` is active.
2. Type a new, non-existing value (e.g., `"Australia, US"`) into the Select
input so that
the quote-aware tokenizer at `Select.tsx:200-208` splits the input and calls
`reconcileTokensRef.current(tokens)` (defined at `Select.tsx:394-424`),
which schedules
the `setTimeout` block at `Select.tsx:398-423`.
3. Before the zero-delay `setTimeout` callback runs, clear the selection (or
remove the
just-created chip) via the `clear` logic starting at `Select.tsx:426`, which
updates
`selectValue` and therefore `selectValueRef.current` to no longer contain
the token value.
4. When the deferred callback at `Select.tsx:398-423` finally runs, it
iterates over the
stale `tokens` array, finds that `hasOption(matchedValue ?? token,
selectValueRef.current)` is now false (because the user cleared it),
constructs an option,
and calls `handleOnSelect` at `Select.tsx:416-420`, re-adding the old token
selection even
though the user has already cleared or changed the input; this demonstrates
stale,
out-of-order state being applied due to the unguarded `setTimeout`-based
reconciliation.
```
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=706c75ed40c04e92b7aa169ca191b952&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=706c75ed40c04e92b7aa169ca191b952&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/Select.tsx
**Line:** 398:423
**Comment:**
*Race Condition: The deferred token reconciliation runs in a
`setTimeout`, so it can execute after newer user actions (like clear/deselect
or additional typing) and re-apply stale tokens out of order. This creates a
race where old input can be selected after the UI has moved on; guard the
callback with a freshness check or cancel prior scheduled reconciliations
before scheduling a new one.
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=88f0d565fdfe850f9cfa29c14523efb29f617b280d2df18d4070a38fb57eba83&reaction=like'>👍</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F39068&comment_hash=88f0d565fdfe850f9cfa29c14523efb29f617b280d2df18d4070a38fb57eba83&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]