Skip to content

Commit

Permalink
Cleanup patches for react navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
Kicu committed Jun 20, 2024
1 parent a29219b commit 85250a6
Showing 1 changed file with 5 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
diff --git a/node_modules/@react-navigation/core/lib/module/useNavigationBuilder.js b/node_modules/@react-navigation/core/lib/module/useNavigationBuilder.js
index 051520b..0ac7357 100644
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,7 @@ export default function useNavigationBuilder(createRouter, options) {
@@ -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 +288,9 @@ export default function useNavigationBuilder(createRouter, options) {
@@ -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(() => {
Expand All @@ -24,11 +23,10 @@ index 051520b..0ac7357 100644
setKey(navigatorKey);
if (!getIsInitial()) {
// If it's not initial render, we need to update the state
@@ -299,15 +299,10 @@ export default function useNavigationBuilder(createRouter, options) {
setState(nextState);
@@ -300,14 +299,10 @@ export default function useNavigationBuilder(createRouter, options) {
}
return () => {
- // We need to clean up state for this navigator on unmount
// 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
Expand All @@ -37,7 +35,6 @@ index 051520b..0ac7357 100644
- cleanUpState();
- }
- }, 0);
+ // We need to clean up state for this navigator on unmount
+ if (getCurrentState() !== undefined && getKey() === navigatorKey) {
+ setCurrentState(undefined);
+ stateCleanedUp.current = true;
Expand Down

0 comments on commit 85250a6

Please sign in to comment.