justinpark commented on PR #21316: URL: https://github.com/apache/superset/pull/21316#issuecomment-1249825555
> > > Is there a reason for removing AsyncSelect useEffect dependencies? > > > > > > michael-s-molina Because fetchPage kept changing while initializing due to the object dependencies, useEffect has been triggered multiple times which causes unnecessary `fetchPage` calls. > > I made [a change](https://github.com/apache/superset/pull/21316/commits/243ba07e55d24eb3c007f58557ddde68dcd139e9) to reduce and fix the dependencies for fetchPage and rollback this useEffect dependencies. > > justinpark We can't add the responsibility of the immutability of the `options` to the Select component because there are some cases where we want to fire the requests again when the function changes. To fix your problem, you just need to make sure `options` only change when you in fact want them to. This is generally accomplished by the use of `useMemo` or `useCallback` on the parent component depending on the case. Okay. @michael-s-molina I finally cleaned up the main cause. 1. I removed [the unnecessary sort function dependency](https://github.com/apache/superset/blob/master/superset-frontend/src/components/Select/AsyncSelect.tsx#L319) on mergeData because fetchOptions resolver only cares the length(so sorting is unnecessary and heavy). https://github.com/apache/superset/blob/b739e27f6dc4b159d766074e3e353a5546d00adb/superset-frontend/src/components/Select/AsyncSelect.tsx#L340-L346 2. I fixed [the invalid checking](https://github.com/apache/superset/blob/master/superset-frontend/src/components/Select/AsyncSelect.tsx#L345) for setAllValuesLoaded. (Since allValuesLoaded should check whether the current request is for the full list or not, it should check the `search` rather than `value) 3. When removes the key in DatabaseSelector, its initial database selection has gone. (#21174) The issue is caused by the missing currentDb mapping when db prop is updated. I added the useEffect logic to handle this issue. https://github.com/apache/superset/blob/b739e27f6dc4b159d766074e3e353a5546d00adb/superset-frontend/src/components/DatabaseSelector/index.tsx#L135-L144 4. Lastly I found the same useEffect logic on AsyncSelect so removed one https://github.com/apache/superset/blob/b739e27f6dc4b159d766074e3e353a5546d00adb/superset-frontend/src/components/Select/AsyncSelect.tsx#L473-L477 https://github.com/apache/superset/blob/b739e27f6dc4b159d766074e3e353a5546d00adb/superset-frontend/src/components/Select/AsyncSelect.tsx#L513-L517 -- 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]
