-
Notifications
You must be signed in to change notification settings - Fork 15.8k
chore(react18): Migrate legacy react methods #34892
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore(react18): Migrate legacy react methods #34892
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review by Korbit AI
Korbit automatically attempts to detect when you fix issues in new commits.
Category | Issue | Status |
---|---|---|
Redundant Object.keys() Computation ▹ view | 🧠 Not in scope |
Files scanned
File Path | Reviewed |
---|---|
superset-frontend/src/components/Datasource/types.ts | ✅ |
superset-frontend/src/dashboard/components/menu/WithPopoverMenu.tsx | ✅ |
superset-frontend/src/explore/components/controls/SelectControl.jsx | ✅ |
superset-frontend/src/dashboard/components/Dashboard.jsx | ✅ |
superset-frontend/src/explore/components/controls/AnnotationLayerControl/index.tsx | ✅ |
superset-frontend/src/components/Datasource/CollectionTable.tsx | ✅ |
superset-frontend/src/explore/components/controls/FilterControl/AdhocFilterControl/index.jsx | ✅ |
superset-frontend/.eslintrc.js | ✅ |
superset-frontend/src/dashboard/components/SliceAdder.tsx | ✅ |
Explore our documentation to understand the languages and file types we support and the files we ignore.
Check out our docs on how you can make Korbit work best for you and your team.
if ( | ||
(Object.keys(annotationError).length && !validationErrors.length) || | ||
(!Object.keys(annotationError).length && validationErrors.length) | ||
) { | ||
if ( | ||
annotationError !== prevProps.annotationError || | ||
validationErrors !== prevProps.validationErrors || | ||
value !== prevProps.value | ||
) { |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potential Improvements
A. getDerivedStateFromProps Usage
getDerivedStateFromProps must return either a new state object or null. The code mostly does this; however, there are cases where it always returns an object, even if nothing changed (e.g., { prevCollection: nextProps.collection }).
Best Practice: Only return the minimal state update if something actually changed.
Impact: This can cause unnecessary re-renders but is technically correct. It’s a minor efficiency concern.
B. State Naming
Adding keys like prevCollection, prevLastUpdated, etc., to state is a common workaround. However, this can make the state object larger and more complex.
Best Practice: If the component only needs to react to changes (not keep a historical value), consider comparing props directly in componentDidUpdate.
Impact: Not a bug, but can increase cognitive load for maintainers.
C. Possible Missed Edge Cases
In some components (e.g., AdhocFilterControl), derived state is always returned, even when not necessary. This may cause extra renders.
In WithPopoverMenu, the derived state always returns { needsClickListner: undefined } if neither condition matches, which may also cause extra renders.
Sounds good. Minimized the getDerievedStateFromProps and use componentDidUpdate instead. |
c7860ba
to
3b4696a
Compare
SUMMARY
This commit migrates legacy lifecycle methods to their newer versions as part of the upgrade process to React 18.
BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
N/A
TESTING INSTRUCTIONS
CI and specs
ADDITIONAL INFORMATION