Components: refactor Notice to pass exhaustive-deps#44157
Merged
Conversation
44 tasks
|
Size Change: 0 B Total Size: 1.26 MB ℹ️ View Unchanged
|
ciampo
reviewed
Sep 14, 2022
Contributor
ciampo
left a comment
There was a problem hiding this comment.
Code-wise the changes seem correct, but we'll need to wait for folks from the native team to test this
Member
|
Hey there 👋
Sure! I'll check it out 👍 |
geriux
approved these changes
Sep 16, 2022
Member
geriux
left a comment
There was a problem hiding this comment.
LGTM! I've tested this on both iOS and Android and it works as expected. 🚀
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?
Refactor the Notice component to ignore the
exhaustive-depseslint rule. This specifically impacts the*.nativeversion of the componentsWhy?
Part of the effort in #41166 to apply
exhuastive-depsto the Components packageHow?
In
index.native.js:Because
startAnimationis not called anywhere else, its code can be moved directly into theuseEffectcall. This eliminates the need forstartAnimationas a dependency, but it brings dependencies of its own:animationValueis actually aRefobject, so it should remain stable and safe to list as a dependencyonHidewould cause endless re-renders, so it gets wrapped in its ownuseCallbackto ensure referencial equality.idis needed as a dependency foronHide's newuseCallback. This should be a unique value to the current notice, and not something that should change (though I lost the thread on tracking it. It looks like it's coming from the@wordpress/noticesstore.)onNoticeHiddenis a dependency of both the originaluseEffectand the newuseCallback. It's a prop passed in fromlist.native.js, and would cause unwanted re-renders, so more changes were needed there.In
list.native.js:onNoticeHiddenwas is being passed theonRemovemethod. To prevent endless re-renders do an unstable reference there, we can wraponRemovein its ownuseCallback. The only dependency here would be theremoveNoticemethod, which should be always be a stable reference because it's a dispatch function.Because all of these changes are in the native components, I lack a good means for testing... @geriux, would you be able to take a look at these changes?
Testing Instructions
npx eslint --rule 'react-hooks/exhaustive-deps: warn' packages/components/src/notice