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


##########
superset-frontend/packages/superset-ui-core/src/components/Select/AsyncSelect.tsx:
##########
@@ -281,6 +298,39 @@ const AsyncSelect = 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) {
+            setSelectOptions(previous =>
+              hasOption(token, previous, true)
+                ? previous
+                : [option, ...previous],
+            );
+          }
+          handleOnSelect(
+            { label: option.label, value: option.value } as AntdLabeledValue,
+            option as AntdLabeledValue,
+          );
+        });
+      });

Review Comment:
   **Suggestion:** This schedules asynchronous state updates via `setTimeout` 
without cancellation, so a pending callback can run after unmount and still 
call state setters/select handlers. Store the timer id and clear it on unmount 
(or avoid `setTimeout`) to prevent post-unmount updates and racey side effects. 
[race condition]
   
   <details>
   <summary><b>Severity Level:</b> Minor 🧹</summary>
   
   ```mdx
   - ⚠️ AsyncSelect may update state after unmount causing warnings.
   - ⚠️ Potential minor memory leak from stale timeout callbacks.
   - ⚠️ Selection side effects might fire after filter removal.
   ```
   </details>
   <details>
   <summary><b>Steps of Reproduction ✅ </b></summary>
   
   ```mdx
   1. Mount the AsyncSelect component defined in
   
`superset-frontend/packages/superset-ui-core/src/components/Select/AsyncSelect.tsx:166`
 in
   multi-select mode (`isSingleMode` false) with `allowNewOptions` true, so 
`mappedMode` is
   `'multiple'` and new options are permitted.
   
   2. Type quoted, separator-containing input (for example `"Australia, US"`) 
into the select
   so antd's Select invokes the function-form `tokenSeparators` provided as
   `quoteAwareTokenSeparators` at `AsyncSelect.tsx:182-191`, which calls
   `reconcileTokensRef.current(tokens)` when tokenization happens.
   
   3. Inside `reconcileTokensRef.current` (AsyncSelect.tsx:305-332), the code 
at line 309
   schedules `setTimeout(() => { ... })`, which later calls `setSelectOptions` 
(lines
   320-324) and `handleOnSelect` (lines 326-328) to add/select options for each 
token.
   
   4. If the parent component unmounts AsyncSelect (for example, navigating 
away or removing
   the filter control) before the timeout fires, the scheduled callback still 
executes after
   unmount and invokes `setSelectOptions` and `handleOnSelect` on an unmounted 
component
   instance, producing React "setState on unmounted component" warnings and 
potentially
   firing selection side effects after the UI has been torn down, since there 
is no cleanup
   or `clearTimeout` for this timer.
   ```
   </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=c7e6e963622f4483b2d7559403cd6a00&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=c7e6e963622f4483b2d7559403cd6a00&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:** 309:331
   **Comment:**
        *Race Condition: This schedules asynchronous state updates via 
`setTimeout` without cancellation, so a pending callback can run after unmount 
and still call state setters/select handlers. Store the timer id and clear it 
on unmount (or avoid `setTimeout`) to prevent post-unmount updates and racey 
side effects.
   
   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=de9f681975664d4912b8dd0a8ab5a34dc4227e479674385f9a77ab10af461fbd&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F39068&comment_hash=de9f681975664d4912b8dd0a8ab5a34dc4227e479674385f9a77ab10af461fbd&reaction=dislike'>👎</a>



##########
superset-frontend/packages/superset-ui-core/src/components/Select/utils.tsx:
##########
@@ -250,3 +259,62 @@ export const mapOptions = (values: SelectOptionsType): 
Record<string, any>[] =>
     key: opt.value,
     ...opt,
   }));
+
+// Splits text by separators, preserving commas inside double quotes.
+export function splitWithQuoteEscaping(
+  text: string,
+  separators: string[],
+): string[] {
+  const separator = separators.find(sep => text.includes(sep));
+  if (!separator) {
+    return [text.trim()].filter(Boolean);

Review Comment:
   **Suggestion:** When no separator is present, quoted input is returned with 
quotes intact, which makes paste behavior inconsistent with the quoted-token 
path and can produce values like `"Canada"` instead of `Canada`. Normalize the 
no-separator branch to also strip surrounding quotes. [logic error]
   
   <details>
   <summary><b>Severity Level:</b> Major ⚠️</summary>
   
   ```mdx
   - ⚠️ Pasted quoted values retain quotes in filter chips.
   - ⚠️ Behavior diverges from other quote-stripping paths.
   - ⚠️ Users may see unexpected quotes in option labels.
   ```
   </details>
   <details>
   <summary><b>Steps of Reproduction ✅ </b></summary>
   
   ```mdx
   1. In the AsyncSelect paste handler at
   
`superset-frontend/packages/superset-ui-core/src/components/Select/AsyncSelect.tsx:752-765`,
   paste a quoted single value like `"Canada"` into a multi-select AsyncSelect 
where
   `tokenSeparators` contains `','`, so `separators` becomes `[',', ...]` and
   `splitWithQuoteEscaping('"Canada"', separators)` is invoked.
   
   2. Inside `splitWithQuoteEscaping` (utils.tsx:263-296), line 268 computes 
`separator =
   separators.find(sep => text.includes(sep))`; because the text does not 
contain a comma,
   `separator` is `undefined`.
   
   3. The branch at lines 269-270 (`if (!separator) { return 
[text.trim()].filter(Boolean);
   }`) executes, returning a single token `'"Canada"'` with its surrounding 
double quotes
   preserved.
   
   4. AsyncSelect's paste logic (AsyncSelect.tsx:752-770) converts this token 
into an option
   chip with label and value `'"Canada"'`, while other flows strip quotes via
   `stripSurroundingQuotes` (for example, in `handleOnSearch` at 
AsyncSelect.tsx:516-524 and
   in `handleFilterOptionHelper` at utils.tsx:213-236), leading to inconsistent 
behavior and
   surprising extra quotes on pasted single values.
   ```
   </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=7972f1469ba24fbfb65cc5b5efec142b&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=7972f1469ba24fbfb65cc5b5efec142b&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/utils.tsx
   **Line:** 269:270
   **Comment:**
        *Logic Error: When no separator is present, quoted input is returned 
with quotes intact, which makes paste behavior inconsistent with the 
quoted-token path and can produce values like `"Canada"` instead of `Canada`. 
Normalize the no-separator branch to also strip surrounding quotes.
   
   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=597d64e7a7152fd44ec37549693ea917ee31f711d27ae8b94800d912796a652d&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F39068&comment_hash=597d64e7a7152fd44ec37549693ea917ee31f711d27ae8b94800d912796a652d&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