justinpark commented on PR #34892:
URL: https://github.com/apache/superset/pull/34892#issuecomment-3234828688
> ## 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.
--
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]