@react-navigation/core 7.0.0 → 7.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/commonjs/useNavigationBuilder.js +15 -1
- package/lib/commonjs/useNavigationBuilder.js.map +1 -1
- package/lib/module/useNavigationBuilder.js +15 -1
- package/lib/module/useNavigationBuilder.js.map +1 -1
- package/lib/typescript/commonjs/src/useNavigationBuilder.d.ts.map +1 -1
- package/lib/typescript/commonjs/tsconfig.build.tsbuildinfo +1 -1
- package/lib/typescript/module/src/useNavigationBuilder.d.ts.map +1 -1
- package/lib/typescript/module/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/useNavigationBuilder.tsx +18 -1
|
@@ -597,8 +597,25 @@ export function useNavigationBuilder<
|
|
|
597
597
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
598
598
|
}, []);
|
|
599
599
|
|
|
600
|
+
// In some cases (e.g. route names change), internal state might have changed
|
|
601
|
+
// But it hasn't been committed yet, so hasn't propagated to the sync external store
|
|
602
|
+
// During this time, we need to return the internal state in `getState`
|
|
603
|
+
// Otherwise it can result in inconsistent state during render in children
|
|
604
|
+
// To avoid this, we use a ref for render phase, and immediately clear it on commit
|
|
605
|
+
const stateRef = React.useRef<State | null>(state);
|
|
606
|
+
|
|
607
|
+
stateRef.current = state;
|
|
608
|
+
|
|
609
|
+
useIsomorphicLayoutEffect(() => {
|
|
610
|
+
stateRef.current = null;
|
|
611
|
+
}, []);
|
|
612
|
+
|
|
600
613
|
const getState = useLatestCallback((): State => {
|
|
601
|
-
|
|
614
|
+
if (stateRef.current != null) {
|
|
615
|
+
return stateRef.current;
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
const currentState = getCurrentState();
|
|
602
619
|
|
|
603
620
|
return deepFreeze(
|
|
604
621
|
(isStateInitialized(currentState)
|