Components: refactor NavigatorScreen
to pass exhaustive-deps
#43876
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
NavigatorScreen
component pass theexhaustive-deps
eslint rule.Why?
Part of the effort in #41166 to apply
exhuastive-deps
to the Components packageHow?
Adding
location.isBack
andpreviousLocation?.focusTargetSelector
to theuseEffect
deps array.This does cause some additional renders on navigation between screens, but they don't appear problematic in my tests. I think they're happening because each time you navigate the
locationHistory changes
. This triggers an update to thegoTo
andgoBack
values that are being drawn from context. This, in turn, causes an update to the context value as a whole (goTo
andgoBack
both appear in theuseMemo
dep array fornavigatorContextValue
). Updating thenavigatorContextValue
means that even if it didn't change on this particular render, alllocation
values are being redeclared, which will trigger a re-render thanks to our new dependencies.All of that said, I know
Navigator
is your brainchild @ciampo so please let me know if that logic sounds flawed! 🙂Testing Instructions
npx eslint --rule 'react-hooks/exhaustive-deps: warn' packages/components/src/navigatior/navigator-screen
navigator
unit tests still passNavigator
component stories and/or docs still work as expected