fix: memoize chip color resolution#4964
Conversation
|
Hey @popsiclelmlm, thank you for your pull request 🤗. The documentation from this branch can be viewed here. |
|
Thanks for the PR. Are you seeing any slowdowns or is this hypothetical? Understanding it is critical to know whether rest of the code should be updated. |
|
Thanks for asking. This isn't based on a benchmark or a user-reported slowdown. I noticed that Chip recalculates derived colors during render, so this PR is a preventative cleanup to avoid repeating that color resolution when the relevant inputs haven't changed. If you'd prefer changes like this to be backed by measured slowdown before merging, I'm happy to close this or keep it scoped to Chip rather than updating similar code elsewhere. |
|
@popsiclelmlm let's close it for now as it'll result in conflicts with ongoing work unnecessarily. happy to merge changes later if we can measure it. |
Motivation
Chipresolves multiple theme-derived colors during render. The current main branch has already removed most of the color chains mentioned in issue #4946, butChipstill callsgetChipColorsevery render even when its color inputs are unchanged.This wraps the color resolution in
React.useMemoso the derived color object is recomputed only when the relevant inputs change. There is no API or visual behavior change.Related issue
Related to #4946.
Test plan
yarn test src/components/__tests__/Chip.test.tsx --runInBandyarn lint-no-fix src/components/Chip/Chip.tsxyarn typescript