Components: refactor CustomGradientBar to pass exhaustive-deps#41463
Merged
Components: refactor CustomGradientBar to pass exhaustive-deps#41463
CustomGradientBar to pass exhaustive-deps#41463Conversation
|
Size Change: +9 B (0%) Total Size: 1.24 MB
ℹ️ View Unchanged
|
44 tasks
mirka
approved these changes
Jun 1, 2022
Member
mirka
left a comment
There was a problem hiding this comment.
While I do wonder whether we would've structured these functions differently (i.e. easier to machine-verify correctness) had the exhaustive-deps rule already been in place, I think this is definitely an improvement!
9578c7c to
dc84cd4
Compare
Contributor
Author
Thanks for highlighting. I'll hold off on merging this and review things again after |
Contributor
|
Just flagging that #41492 has been merged — let's rebase and give this PR a final round of reviews :) |
957d031 to
8ca2eb2
Compare
Contributor
Author
|
Rebased and not seeing any new/unexpected behavior. Let me know what you think @ciampo/@mirka! |
…entPickerDomRef` in `useMemo` dependencies
…entListeners` function
16c57bc to
86b149b
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What?
Updates the
CustomGradientBarcomponent to satisfy theexhaustive-depseslint rule (specifically by updating theControlPointssubcomponent)Why?
Part of the effort in #41166 to apply
exhuastive-depsto the Components packageHow?
GradientPickerDropdown
Update the
popoverPropsuseMemodependency array to includegradientPickerDomRefinstead ofgradientPickerDomRef.current.useEffectto clean event listeners on unmountThe dependency array is currently empty, which works to trigger the cleanup only on unmount. Unfortunately
exhaustive-depsexpects to see the function being called in the dependency array, which would cause it to trigger on every render.To avoid that, if we wrap
cleanEventListenersin its ownuseCallbackthe listeners aren't able to be cleaned properly. Using a ref of the function instead allows us to exclude it from the dependency array so ouruseEffectcan provide the intended cleanup, without disrupting the actual user interactions with the component.Took me a little bit to arrive at this solution, and I'm very open to feedback if there are other/better approaches :)
Testing Instructions
npx eslint --rule 'react-hooks/exhaustive-deps: warn' packages/components/src/custom-gradient-bar