Skip to content

Conversation

justinpark
Copy link
Member

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

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

@dosubot dosubot bot added the frontend:refactor Related to refactoring the frontend label Aug 28, 2025
Copy link

@korbit-ai korbit-ai bot left a 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
Performance 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.

Loving Korbit!? Share us on LinkedIn Reddit and X

Comment on lines +112 to +120
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.

Copy link
Member

@michael-s-molina michael-s-molina left a 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.

@justinpark
Copy link
Member Author

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.

@justinpark justinpark force-pushed the chore--refactor-legacy-react-method-for-react18 branch from c7860ba to 3b4696a Compare September 23, 2025 23:03
@justinpark justinpark merged commit 7f38405 into apache:master Sep 24, 2025
62 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
frontend:refactor Related to refactoring the frontend size/L
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants