expo-router 2.0.7 → 2.0.9

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.
@@ -1,3 +1,9 @@
1
1
  export declare function useWarnOnce(message: string, guard?: unknown, key?: string): void;
2
- export declare function useDeprecated(message: string, guard?: unknown, key?: string): void;
2
+ export declare function useDeprecated(
3
+ /** The deprecated message to display */
4
+ message: string,
5
+ /** The guard to cause the warning to being displayed */
6
+ guard?: unknown,
7
+ /** The key to use for the warning. Used to detect if the warning has already been shown. */
8
+ key?: string): void;
3
9
  //# sourceMappingURL=useDeprecated.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useDeprecated.d.ts","sourceRoot":"","sources":["../src/useDeprecated.ts"],"names":[],"mappings":"AAaA,wBAAgB,WAAW,CACzB,OAAO,EAAE,MAAM,EACf,KAAK,GAAE,OAAc,EACrB,GAAG,SAAU,QAUd;AAED,wBAAgB,aAAa,CAC3B,OAAO,EAAE,MAAM,EACf,KAAK,GAAE,OAAc,EACrB,GAAG,SAAU,QAGd"}
1
+ {"version":3,"file":"useDeprecated.d.ts","sourceRoot":"","sources":["../src/useDeprecated.ts"],"names":[],"mappings":"AAaA,wBAAgB,WAAW,CACzB,OAAO,EAAE,MAAM,EACf,KAAK,GAAE,OAAc,EACrB,GAAG,SAAU,QAUd;AAED,wBAAgB,aAAa;AAC3B,wCAAwC;AACxC,OAAO,EAAE,MAAM;AACf,wDAAwD;AACxD,KAAK,GAAE,OAAc;AACrB,4FAA4F;AAC5F,GAAG,SAAU,QAGd"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expo-router",
3
- "version": "2.0.7",
3
+ "version": "2.0.9",
4
4
  "main": "src/index.tsx",
5
5
  "types": "build/index.d.ts",
6
6
  "files": [
@@ -105,12 +105,12 @@
105
105
  },
106
106
  "dependencies": {
107
107
  "@bacons/react-views": "^1.1.3",
108
- "@expo/metro-runtime": "2.2.9",
108
+ "@expo/metro-runtime": "2.2.11",
109
109
  "@radix-ui/react-slot": "1.0.1",
110
110
  "@react-navigation/bottom-tabs": "~6.5.7",
111
111
  "@react-navigation/native": "~6.1.6",
112
112
  "@react-navigation/native-stack": "~6.9.12",
113
- "expo-head": "0.0.13",
113
+ "expo-head": "0.0.15",
114
114
  "expo-splash-screen": "~0.20.2",
115
115
  "query-string": "7.1.3",
116
116
  "react-helmet-async": "^1.3.0",
@@ -75,9 +75,11 @@ export function linkTo(this: RouterStore, href: string, event?: string) {
75
75
  return;
76
76
  }
77
77
 
78
+ const rootState = navigationRef.getRootState();
79
+
78
80
  if (href.startsWith(".")) {
79
81
  let base =
80
- this.linking.getPathFromState?.(navigationRef.getRootState(), {
82
+ this.linking.getPathFromState?.(rootState, {
81
83
  screens: [],
82
84
  preserveGroups: true,
83
85
  }) ?? "";
@@ -99,11 +101,9 @@ export function linkTo(this: RouterStore, href: string, event?: string) {
99
101
 
100
102
  switch (event) {
101
103
  case "REPLACE":
102
- return navigationRef.dispatch(
103
- getNavigateReplaceAction(state, navigationRef.getRootState())
104
- );
104
+ return navigationRef.dispatch(getNavigateReplaceAction(state, rootState));
105
105
  default:
106
- return navigationRef.dispatch(getNavigatePushAction(state));
106
+ return navigationRef.dispatch(getNavigatePushAction(state, rootState));
107
107
  }
108
108
  }
109
109
 
@@ -121,19 +121,22 @@ function rewriteNavigationStateToParams(
121
121
  const lastRoute = state.routes.at(-1)!;
122
122
  params.screen = lastRoute.name;
123
123
  // Weirdly, this always needs to be an object. If it's undefined, it won't work.
124
- params.params = lastRoute.params ?? {};
124
+ params.params = lastRoute.params
125
+ ? JSON.parse(JSON.stringify(lastRoute.params))
126
+ : {};
125
127
 
126
128
  if (lastRoute.state) {
127
129
  rewriteNavigationStateToParams(lastRoute.state, params.params);
128
130
  }
129
131
 
130
- return params;
132
+ return JSON.parse(JSON.stringify(params));
131
133
  }
132
134
 
133
- function getNavigatePushAction(state: ResultState) {
135
+ function getNavigatePushAction(state: ResultState, rootState: NavigationState) {
134
136
  const { screen, params } = rewriteNavigationStateToParams(state);
135
137
  return {
136
138
  type: "NAVIGATE",
139
+ target: rootState.key,
137
140
  payload: {
138
141
  name: screen,
139
142
  params,
@@ -142,12 +145,12 @@ function getNavigatePushAction(state: ResultState) {
142
145
  }
143
146
 
144
147
  function getNavigateReplaceAction(
145
- previousState: ResultState,
148
+ state: ResultState,
146
149
  parentState: NavigationState,
147
150
  lastNavigatorSupportingReplace: NavigationState = parentState
148
151
  ): NavigationAction {
149
152
  // We should always have at least one route in the state
150
- const state = previousState.routes.at(-1)!;
153
+ const route = state.routes.at(-1)!;
151
154
 
152
155
  // Only these navigators support replace
153
156
  if (parentState.type === "stack" || parentState.type === "tab") {
@@ -155,29 +158,29 @@ function getNavigateReplaceAction(
155
158
  }
156
159
 
157
160
  const currentRoute = parentState.routes.find(
158
- (route) => route.name === state.name
161
+ (parentRoute) => parentRoute.name === route.name
159
162
  );
160
163
  const routesAreEqual = parentState.routes[parentState.index] === currentRoute;
161
164
 
162
165
  // If there is nested state and the routes are equal, we should keep going down the tree
163
- if (state.state && routesAreEqual && currentRoute.state) {
166
+ if (route.state && routesAreEqual && currentRoute.state) {
164
167
  return getNavigateReplaceAction(
165
- state.state,
168
+ route.state,
166
169
  currentRoute.state as any,
167
170
  lastNavigatorSupportingReplace
168
171
  );
169
172
  }
170
173
 
171
174
  // Either we reached the bottom of the state or the point where the routes diverged
172
- const { screen, params } = rewriteNavigationStateToParams(previousState);
175
+ const { screen, params } = rewriteNavigationStateToParams(state);
176
+
173
177
  return {
174
178
  type:
175
179
  lastNavigatorSupportingReplace.type === "stack" ? "REPLACE" : "JUMP_TO",
180
+ target: lastNavigatorSupportingReplace?.key,
176
181
  payload: {
177
182
  name: screen,
178
183
  params,
179
- // Ensure that the last navigator supporting replace is the one that handles the action
180
- source: lastNavigatorSupportingReplace?.key,
181
184
  },
182
185
  };
183
186
  }
@@ -17,7 +17,7 @@ export function useWarnOnce(
17
17
  key = message
18
18
  ) {
19
19
  // useLayoutEffect typically doesn't run in node environments.
20
- // Combined with skipWarn, this should prevent unwanted warnings
20
+ // Combined with skipWarn, this should prevent unwanted warnings during SSR rendering
21
21
  useLayoutEffect(() => {
22
22
  if (guard && canWarn && !warned.has(key)) {
23
23
  warned.add(key);
@@ -27,8 +27,11 @@ export function useWarnOnce(
27
27
  }
28
28
 
29
29
  export function useDeprecated(
30
+ /** The deprecated message to display */
30
31
  message: string,
32
+ /** The guard to cause the warning to being displayed */
31
33
  guard: unknown = true,
34
+ /** The key to use for the warning. Used to detect if the warning has already been shown. */
32
35
  key = message
33
36
  ) {
34
37
  return useWarnOnce(key, guard, `Expo Router: ${message}`);
@@ -48,7 +48,7 @@ export function Screen<TOptions extends object = object>({
48
48
  // eslint-disable-next-line react-hooks/rules-of-hooks
49
49
  useDeprecated(
50
50
  "The `redirect` prop on <Screen /> is deprecated and will be removed. Please use `router.redirect` instead",
51
- redirect
51
+ Boolean(redirect)
52
52
  );
53
53
  }
54
54