@react-navigation/core 7.0.0 → 7.0.1

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.
@@ -597,7 +597,24 @@ 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 => {
614
+ if (stateRef.current != null) {
615
+ return stateRef.current;
616
+ }
617
+
601
618
  const currentState = shouldUpdate ? nextState : getCurrentState();
602
619
 
603
620
  return deepFreeze(