@react-navigation/core 7.21.2 → 7.21.4

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.
Files changed (72) hide show
  1. package/lib/module/PreventRemoveContext.js.map +1 -1
  2. package/lib/module/PreventRemoveProvider.js +34 -24
  3. package/lib/module/PreventRemoveProvider.js.map +1 -1
  4. package/lib/module/createNavigationContainerRef.js +6 -8
  5. package/lib/module/createNavigationContainerRef.js.map +1 -1
  6. package/lib/module/getStateFromPath.js +82 -58
  7. package/lib/module/getStateFromPath.js.map +1 -1
  8. package/lib/module/useEventEmitter.js +1 -1
  9. package/lib/module/useEventEmitter.js.map +1 -1
  10. package/lib/module/useKeyedChildListeners.js +4 -2
  11. package/lib/module/useKeyedChildListeners.js.map +1 -1
  12. package/lib/module/useNavigationBuilder.js +3 -15
  13. package/lib/module/useNavigationBuilder.js.map +1 -1
  14. package/lib/module/useNavigationCache.js +5 -2
  15. package/lib/module/useNavigationCache.js.map +1 -1
  16. package/lib/module/useNavigationHelpers.js +27 -9
  17. package/lib/module/useNavigationHelpers.js.map +1 -1
  18. package/lib/module/useNavigationState.js +1 -1
  19. package/lib/module/useNavigationState.js.map +1 -1
  20. package/lib/module/useOnAction.js +1 -1
  21. package/lib/module/useOnAction.js.map +1 -1
  22. package/lib/module/useOptionsGetters.js +3 -1
  23. package/lib/module/useOptionsGetters.js.map +1 -1
  24. package/lib/module/usePreventRemove.js +9 -2
  25. package/lib/module/usePreventRemove.js.map +1 -1
  26. package/lib/module/useRouteCache.js +14 -7
  27. package/lib/module/useRouteCache.js.map +1 -1
  28. package/lib/module/useScheduleUpdate.js +8 -8
  29. package/lib/module/useScheduleUpdate.js.map +1 -1
  30. package/lib/module/useSyncState.js +4 -1
  31. package/lib/module/useSyncState.js.map +1 -1
  32. package/lib/typescript/src/PreventRemoveContext.d.ts +1 -0
  33. package/lib/typescript/src/PreventRemoveContext.d.ts.map +1 -1
  34. package/lib/typescript/src/PreventRemoveProvider.d.ts.map +1 -1
  35. package/lib/typescript/src/StaticNavigation.d.ts +2 -2
  36. package/lib/typescript/src/StaticNavigation.d.ts.map +1 -1
  37. package/lib/typescript/src/createNavigationContainerRef.d.ts.map +1 -1
  38. package/lib/typescript/src/getStateFromPath.d.ts.map +1 -1
  39. package/lib/typescript/src/types.d.ts +3 -3
  40. package/lib/typescript/src/types.d.ts.map +1 -1
  41. package/lib/typescript/src/useKeyedChildListeners.d.ts.map +1 -1
  42. package/lib/typescript/src/useNavigationBuilder.d.ts.map +1 -1
  43. package/lib/typescript/src/useNavigationCache.d.ts.map +1 -1
  44. package/lib/typescript/src/useNavigationHelpers.d.ts +2 -3
  45. package/lib/typescript/src/useNavigationHelpers.d.ts.map +1 -1
  46. package/lib/typescript/src/useOptionsGetters.d.ts.map +1 -1
  47. package/lib/typescript/src/usePreventRemove.d.ts.map +1 -1
  48. package/lib/typescript/src/usePreventRemoveContext.d.ts +1 -0
  49. package/lib/typescript/src/usePreventRemoveContext.d.ts.map +1 -1
  50. package/lib/typescript/src/useRouteCache.d.ts.map +1 -1
  51. package/lib/typescript/src/useScheduleUpdate.d.ts +5 -4
  52. package/lib/typescript/src/useScheduleUpdate.d.ts.map +1 -1
  53. package/lib/typescript/src/useSyncState.d.ts.map +1 -1
  54. package/package.json +2 -2
  55. package/src/PreventRemoveContext.tsx +1 -0
  56. package/src/PreventRemoveProvider.tsx +48 -43
  57. package/src/StaticNavigation.tsx +2 -2
  58. package/src/createNavigationContainerRef.tsx +12 -9
  59. package/src/getStateFromPath.tsx +112 -74
  60. package/src/types.tsx +18 -16
  61. package/src/useEventEmitter.tsx +1 -1
  62. package/src/useKeyedChildListeners.tsx +4 -2
  63. package/src/useNavigationBuilder.tsx +2 -16
  64. package/src/useNavigationCache.tsx +6 -2
  65. package/src/useNavigationHelpers.tsx +26 -9
  66. package/src/useNavigationState.tsx +1 -1
  67. package/src/useOnAction.tsx +1 -1
  68. package/src/useOptionsGetters.tsx +4 -1
  69. package/src/usePreventRemove.tsx +11 -2
  70. package/src/useRouteCache.tsx +19 -11
  71. package/src/useScheduleUpdate.tsx +8 -7
  72. package/src/useSyncState.tsx +5 -1
@@ -5,19 +5,20 @@ import { useClientLayoutEffect } from './useClientLayoutEffect';
5
5
 
6
6
  /**
7
7
  * When screen config changes, we want to update the navigator in the same update phase.
8
- * However, navigation state is in the root component and React won't let us update it from a child.
9
- * This is a workaround for that, the scheduled update is stored in the ref without actually calling setState.
10
- * It lets all subsequent updates access the latest state so it stays correct.
11
- * Then we call setState during after the component updates.
8
+ * However, navigation state is in the root component and React won't let us update it from a child during render.
9
+ * The render could also be interrupted in concurrent mode, so we need to update after commit.
10
+ * So we queue the update in an insertion effect and flush it in a layout effect.
11
+ * Insertion effects run before layout effects, so every navigator in the tree has queued its update before we flush.
12
+ * This lets nested updates be applied from the root down without clobbering each other.
12
13
  */
13
14
  export function useScheduleUpdate(callback: () => void) {
14
15
  const { scheduleUpdate, flushUpdates } = React.useContext(
15
16
  NavigationBuilderContext
16
17
  );
17
18
 
18
- // FIXME: This is potentially unsafe
19
- // However, since we are using sync store, it might be fine
20
- scheduleUpdate(callback);
19
+ React.useInsertionEffect(() => {
20
+ scheduleUpdate(callback);
21
+ });
21
22
 
22
23
  useClientLayoutEffect(flushUpdates);
23
24
  }
@@ -87,7 +87,11 @@ export function useSyncState<T>(getInitialState: () => T) {
87
87
 
88
88
  if (pendingUpdates.length !== 0) {
89
89
  store.batchUpdates(() => {
90
- // Flush all the pending updates
90
+ // Updates are queued child-first as insertion effects run bottom-up.
91
+ // The root navigator replaces the whole state while nested navigators merge into it.
92
+ // So we apply them root-first to avoid the root clobbering nested updates.
93
+ pendingUpdates.reverse();
94
+
91
95
  for (const update of pendingUpdates) {
92
96
  update();
93
97
  }