-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: patch react-navigation to perform async cleanup as prior to Stri…
…ctMode enabling
- Loading branch information
1 parent
fadfc2c
commit 9bc4bc1
Showing
1 changed file
with
52 additions
and
0 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
patches/@react-navigation+core+6.4.11+002+proper-navigator-unmount-in-strict-mode.patch
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
diff --git a/node_modules/@react-navigation/core/lib/module/useNavigationBuilder.js b/node_modules/@react-navigation/core/lib/module/useNavigationBuilder.js | ||
index 6fb49e0..1f7c859 100644 | ||
--- a/node_modules/@react-navigation/core/lib/module/useNavigationBuilder.js | ||
+++ b/node_modules/@react-navigation/core/lib/module/useNavigationBuilder.js | ||
@@ -114,6 +114,16 @@ const getRouteConfigsFromChildren = (children, groupKey, groupOptions) => { | ||
return configs; | ||
}; | ||
|
||
+const useFullyMountedRef = () => { | ||
+ const isFullyMountedRef = React.useRef(false); | ||
+ | ||
+ React.useEffect(() => { | ||
+ isFullyMountedRef.current = true; | ||
+ }, []); | ||
+ | ||
+ return isFullyMountedRef; | ||
+}; | ||
+ | ||
/** | ||
* Hook for building navigators. | ||
* | ||
@@ -122,6 +132,7 @@ const getRouteConfigsFromChildren = (children, groupKey, groupOptions) => { | ||
* @returns An object containing `state`, `navigation`, `descriptors` objects. | ||
*/ | ||
export default function useNavigationBuilder(createRouter, options) { | ||
+ const isFullyMountedRef = useFullyMountedRef(); | ||
const navigatorKey = useRegisterNavigator(); | ||
const route = React.useContext(NavigationRouteContext); | ||
const { | ||
@@ -298,10 +309,18 @@ export default function useNavigationBuilder(createRouter, options) { | ||
setState(nextState); | ||
} | ||
return () => { | ||
- // We need to clean up state for this navigator on unmount | ||
- if (getCurrentState() !== undefined && getKey() === navigatorKey) { | ||
- setCurrentState(undefined); | ||
- stateCleanedUp.current = true; | ||
+ const cleanup = () => { | ||
+ // We need to clean up state for this navigator on unmount | ||
+ if (getCurrentState() !== undefined && getKey() === navigatorKey) { | ||
+ setCurrentState(undefined); | ||
+ stateCleanedUp.current = true; | ||
+ } | ||
+ } | ||
+ | ||
+ if (!isFullyMountedRef.current) { | ||
+ cleanup(); | ||
+ } else { | ||
+ setTimeout(cleanup, 0); | ||
} | ||
}; | ||
// eslint-disable-next-line react-hooks/exhaustive-deps |