Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[No QA] Update react-navigation StrictMode patch to work also for native apps #44726

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,48 @@ index 051520b..6fb49e0 100644
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
diff --git a/node_modules/@react-navigation/core/src/useNavigationBuilder.tsx b/node_modules/@react-navigation/core/src/useNavigationBuilder.tsx
index b1971ba..7d550e0 100644
--- a/node_modules/@react-navigation/core/src/useNavigationBuilder.tsx
+++ b/node_modules/@react-navigation/core/src/useNavigationBuilder.tsx
@@ -362,11 +362,6 @@ export default function useNavigationBuilder<

const stateCleanedUp = React.useRef(false);

- const cleanUpState = React.useCallback(() => {
- setCurrentState(undefined);
- stateCleanedUp.current = true;
- }, [setCurrentState]);
-
const setState = React.useCallback(
(state: NavigationState | PartialState<NavigationState> | undefined) => {
if (stateCleanedUp.current) {
@@ -540,6 +535,9 @@ export default function useNavigationBuilder<
state = nextState;

React.useEffect(() => {
+ // In strict mode, React will double-invoke effects.
+ // So we need to reset the flag if component was not unmounted
+ stateCleanedUp.current = false;
setKey(navigatorKey);

if (!getIsInitial()) {
@@ -551,14 +549,10 @@ export default function useNavigationBuilder<

return () => {
// We need to clean up state for this navigator on unmount
- // We do it in a timeout because we need to detect if another navigator mounted in the meantime
- // For example, if another navigator has started rendering, we should skip cleanup
- // Otherwise, our cleanup step will cleanup state for the other navigator and re-initialize it
- setTimeout(() => {
- if (getCurrentState() !== undefined && getKey() === navigatorKey) {
- cleanUpState();
- }
- }, 0);
+ if (getCurrentState() !== undefined && getKey() === navigatorKey) {
+ setCurrentState(undefined);
+ stateCleanedUp.current = true;
+ }
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
Loading