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


##########
superset-frontend/packages/superset-ui-core/src/components/Select/AsyncSelect.tsx:
##########
@@ -626,14 +642,16 @@ const AsyncSelect = forwardRef(
       setAllValuesLoaded(false);
     };
 
-    useImperativeHandle(
-      ref,
-      () => ({
-        ...(ref.current as RefSelectProps),
+    useImperativeHandle(ref, () => {
+      const current =
+        ref && typeof ref !== 'function' && ref.current
+          ? (ref.current as RefSelectProps)
+          : ({} as RefSelectProps);
+      return {
+        ...current,
         clearCache,
-      }),
-      [ref],
-    );
+      };
+    }, [ref]);

Review Comment:
   **Suggestion:** The forwarded ref handle is built from `ref.current` and 
then frozen with `[ref]`, but on mount `ref.current` is typically null and this 
callback won't re-run when the inner AntD select instance becomes available. As 
a result, consumers can lose standard `RefSelectProps` methods (like 
`focus`/`blur`) and receive a partial ref object. Use a separate internal ref 
for the underlying select and expose `clearCache` by merging with that internal 
ref inside `useImperativeHandle`. [api mismatch]
   
   <details>
   <summary><b>Severity Level:</b> Major ⚠️</summary>
   
   ```mdx
   - ❌ AsyncSelect ref may omit focus/blur from RefSelectProps.
   - ⚠️ External consumers relying on select ref API can break.
   - ⚠️ Storybook and apps cannot safely use imperative methods.
   ```
   </details>
   <details>
   <summary><b>Steps of Reproduction ✅ </b></summary>
   
   ```mdx
   1. In
   
`superset-frontend/packages/superset-ui-core/src/components/Select/types.ts:187-189`,
 the
   `AsyncSelectRef` type is declared as `RefSelectProps & { clearCache: () => 
void; }`,
   promising that any `ref` attached to `AsyncSelect` exposes the full AntD 
`RefSelectProps`
   API (e.g. `focus`, `blur`) plus `clearCache`.
   
   2. The `AsyncSelect` implementation in
   
`superset-frontend/packages/superset-ui-core/src/components/Select/AsyncSelect.tsx:152-154`
   is a `forwardRef` component taking `ref: ForwardedRef<AsyncSelectRef>` and 
passing that
   same `ref` straight through to the underlying AntD select wrapper via 
`<StyledSelect ...
   ref={ref} />` at `AsyncSelect.tsx:777-785`.
   
   3. The same forwarded `ref` is also customized with `useImperativeHandle` at
   `AsyncSelect.tsx:645-654`, where the handle is built from `ref.current` at 
that moment and
   frozen with a dependency array of `[ref]`. On initial mount, before the 
inner AntD
   `<StyledSelect>` has populated `ref.current` with its `RefSelectProps` 
instance,
   `ref.current` is `null`/undefined, so the created handle effectively becomes 
`{ clearCache
   }` and is never recomputed when the inner select instance later attaches.
   
   4. Any consumer that follows the exported typing contract by doing `const 
ref =
   useRef<AsyncSelectRef>(null);` and rendering `<AsyncSelect ref={ref} ... />` 
(see similar
   pattern in Storybook at `AsyncSelect.stories.tsx:160-166`) and then calling
   `ref.current?.focus()` will receive an object that only has `clearCache` and 
lacks the
   standard `RefSelectProps` methods, breaking the expected API surface for the 
`AsyncSelect`
   ref.
   ```
   </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=51efcb431fc54898bdd26f794e1d0068&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=51efcb431fc54898bdd26f794e1d0068&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:** 645:654
   **Comment:**
        *Api Mismatch: The forwarded ref handle is built from `ref.current` and 
then frozen with `[ref]`, but on mount `ref.current` is typically null and this 
callback won't re-run when the inner AntD select instance becomes available. As 
a result, consumers can lose standard `RefSelectProps` methods (like 
`focus`/`blur`) and receive a partial ref object. Use a separate internal ref 
for the underlying select and expose `clearCache` by merging with that internal 
ref inside `useImperativeHandle`.
   
   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%2F39535&comment_hash=393a9681e0c7804d51347763fe2a61dcbb853bb2e91c147e44e356ff6c8fee34&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F39535&comment_hash=393a9681e0c7804d51347763fe2a61dcbb853bb2e91c147e44e356ff6c8fee34&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