forked from Expensify/App
-
Notifications
You must be signed in to change notification settings - Fork 0
/
@react-navigation+core+6.4.11+001+fix-react-strictmode.patch
89 lines (84 loc) · 4.06 KB
/
@react-navigation+core+6.4.11+001+fix-react-strictmode.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
diff --git a/node_modules/@react-navigation/core/lib/module/useNavigationBuilder.js b/node_modules/@react-navigation/core/lib/module/useNavigationBuilder.js
index 051520b..6fb49e0 100644
--- a/node_modules/@react-navigation/core/lib/module/useNavigationBuilder.js
+++ b/node_modules/@react-navigation/core/lib/module/useNavigationBuilder.js
@@ -174,10 +174,6 @@ export default function useNavigationBuilder(createRouter, options) {
getIsInitial
} = React.useContext(NavigationStateContext);
const stateCleanedUp = React.useRef(false);
- const cleanUpState = React.useCallback(() => {
- setCurrentState(undefined);
- stateCleanedUp.current = true;
- }, [setCurrentState]);
const setState = React.useCallback(state => {
if (stateCleanedUp.current) {
// State might have been already cleaned up due to unmount
@@ -291,6 +287,9 @@ export default function useNavigationBuilder(createRouter, options) {
// So we override the state object we return to use the latest state as soon as possible
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()) {
// If it's not initial render, we need to update the state
@@ -300,14 +299,10 @@ export default function useNavigationBuilder(createRouter, options) {
}
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
}, []);
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
}, []);