Copilot commented on code in PR #35218:
URL: https://github.com/apache/superset/pull/35218#discussion_r2524517212


##########
superset-frontend/packages/superset-ui-core/src/components/Select/Select.tsx:
##########
@@ -400,7 +400,11 @@ const Select = forwardRef(
       onSearch?.(searchValue);
     }, Constants.FAST_DEBOUNCE);
 
-    useEffect(() => () => handleOnSearch.cancel(), [handleOnSearch]);
+    useEffect(() => {
+      if (handleOnSearch !== undefined) {
+        handleOnSearch.cancel();
+      }

Review Comment:
   The useEffect is missing a cleanup function return. Currently, 
`handleOnSearch.cancel()` is called immediately when the effect runs (i.e., 
whenever `handleOnSearch` changes), instead of being called during cleanup when 
the component unmounts.
   
   This should be:
   ```tsx
   useEffect(() => {
     return () => {
       if (handleOnSearch !== undefined) {
         handleOnSearch.cancel();
       }
     };
   }, [handleOnSearch]);
   ```
   
   Or more concisely:
   ```tsx
   useEffect(() => () => handleOnSearch?.cancel(), [handleOnSearch]);
   ```
   ```suggestion
         return () => {
           if (handleOnSearch !== undefined) {
             handleOnSearch.cancel();
           }
         };
   ```



-- 
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