-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
fix(dropdown): stabilize internal references to reduce re-renders #17952
fix(dropdown): stabilize internal references to reduce re-renders #17952
Conversation
✅ Deploy Preview for v11-carbon-web-components ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
✅ Deploy Preview for carbon-elements ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
✅ Deploy Preview for v11-carbon-react ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #17952 +/- ##
==========================================
+ Coverage 81.81% 81.82% +0.01%
==========================================
Files 406 406
Lines 14053 14070 +17
Branches 4405 4409 +4
==========================================
+ Hits 11497 11513 +16
Misses 2394 2394
- Partials 162 163 +1 ☔ View full report in Codecov by Sentry. |
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.
looks good to me!
I'll need to remove the test story before this can merge |
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.
🔥 LGTM!
4b77a2a
Closes #17897
This makes Dropdown's internal references (variables, functions, props, etc) more stable to reduce re-renders by ~98% 🤯
Changelog
Changed
stateReducer
to be delcared outside of the componentonSelectedItemChange
inuseCallback
readOnlyEventHandlers
, and wrap theonKeyDownHandler
it uses withuseCallback
normalizedSlug
that clones theslug
prop and forces themini
sizestateReducer
by returningstate
directly instead of a new object every time (this alone was a huge improvement)items
selectProps
and all the props passed in (isItemDisabled
,onHighlightedIndexChange
)toggleButtonProps
enableFloatingStyles
to the dependency array to ensuremenuProps
will get updatedTesting / Reviewing
Click to expand test results
The benchmark I tested against is the original bug repro with the following interactions, resulting in 4674 renders.
2024-11-01.at.13.45.43-MAIN-Google.Chrome.mp4
The first commit reduces this same interaction to 2145 renders.
2024-11-01.at.14.11.22-MAIN-Google.Chrome.mp4
The second commit is even better, down to just 89 renders.
2024-11-01.at.14.51.19-MAIN-Google.Chrome.mp4
The first two counts are somewhat of an incorrect count because they're tied to mousemove interaction. The update to
stateReducer
is what pulled that down so significantly.