Repository navigation
Conversation
The navigation preset's useNavigation(), useRoute() and useTheme() throw outside a render, as React Navigation's own hooks do, instead of returning a default that also hid hook errors inside a render. Reanimated's corrected hooks still answer outside a render, as Reanimated's own mock does, but now recognise it from React's dispatcher (null, or the context-only one left between renders) and catch nothing. Carries #757's changes onto main. Fixes #747.
…ck does not cover
…ynchronous renderHook
2 tasks
This branch has not been deployed
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.
Summary
The navigation preset's
useNavigation(),useRoute()anduseTheme()throw outside a render, as React Navigation's own hooks do, instead of returning a default. Reanimated's corrected hooks still answer outside a render, as Reanimated's own mock does, but no longer catch any error from React. Closes #747.Why
The catches also hid hook errors inside a render. With a second copy of React,
useTheme()returnedDefaultTheme, and a test asserting a themed colour failed with "Unable to find an element", far from the cause.Changes
useNavigationBuilder().describe()reuses the navigation its render read, rather than calling a hook after the render.useRefOrNullrecognises "outside a render" from React's dispatcher: null before any render, or the context-only one React leaves between renders. Otherwise it callsuseRefwith notry/catch.Notes
main. Its stacked base (fix(hot): preset factories build their mocks with the test file's React #756) has merged. Unlike fix(presets): navigation hooks throw outside a render instead of returning a default #757, Reanimated's fallback no longer matches React's "Invalid hook call" message, so that error also propagates inside a render.PRESET_REACT_MISMATCHrefuses a copy resolved from another path. The mock engine doesn't check, and neither engine sees two instances of one React file; see Preset hooks can't tell a second React rendering from no render #968.