@tanstack/react-router 0.0.1-beta.182 → 0.0.1-beta.184

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.
@@ -11,19 +11,19 @@
11
11
  "children": [
12
12
  {
13
13
  "name": "@tanstack+store@0.0.1/node_modules/@tanstack/store/build/esm/index.js",
14
- "uid": "ff99-159"
14
+ "uid": "497b-159"
15
15
  },
16
16
  {
17
17
  "name": "@tanstack+react-store@0.0.1/node_modules/@tanstack/react-store/build/esm/index.js",
18
- "uid": "ff99-161"
18
+ "uid": "497b-161"
19
19
  },
20
20
  {
21
21
  "name": "tiny-invariant@1.3.1/node_modules/tiny-invariant/dist/esm/tiny-invariant.js",
22
- "uid": "ff99-163"
22
+ "uid": "497b-163"
23
23
  },
24
24
  {
25
25
  "name": "tiny-warning@1.0.3/node_modules/tiny-warning/dist/tiny-warning.esm.js",
26
- "uid": "ff99-165"
26
+ "uid": "497b-165"
27
27
  }
28
28
  ]
29
29
  },
@@ -32,25 +32,25 @@
32
32
  "children": [
33
33
  {
34
34
  "name": "router-core/build/esm/index.js",
35
- "uid": "ff99-167"
35
+ "uid": "497b-167"
36
36
  },
37
37
  {
38
38
  "name": "react-router/src",
39
39
  "children": [
40
40
  {
41
- "uid": "ff99-171",
41
+ "uid": "497b-171",
42
42
  "name": "react.tsx"
43
43
  },
44
44
  {
45
- "uid": "ff99-173",
45
+ "uid": "497b-173",
46
46
  "name": "scroll-restoration.tsx"
47
47
  },
48
48
  {
49
- "uid": "ff99-175",
49
+ "uid": "497b-175",
50
50
  "name": "awaited.tsx"
51
51
  },
52
52
  {
53
- "uid": "ff99-177",
53
+ "uid": "497b-177",
54
54
  "name": "index.tsx"
55
55
  }
56
56
  ]
@@ -58,7 +58,7 @@
58
58
  ]
59
59
  },
60
60
  {
61
- "uid": "ff99-169",
61
+ "uid": "497b-169",
62
62
  "name": "\u0000rollupPluginBabelHelpers.js"
63
63
  }
64
64
  ]
@@ -67,302 +67,302 @@
67
67
  "isRoot": true
68
68
  },
69
69
  "nodeParts": {
70
- "ff99-159": {
70
+ "497b-159": {
71
71
  "renderedLength": 1843,
72
72
  "gzipLength": 644,
73
73
  "brotliLength": 0,
74
- "mainUid": "ff99-158"
74
+ "mainUid": "497b-158"
75
75
  },
76
- "ff99-161": {
76
+ "497b-161": {
77
77
  "renderedLength": 1006,
78
78
  "gzipLength": 479,
79
79
  "brotliLength": 0,
80
- "mainUid": "ff99-160"
80
+ "mainUid": "497b-160"
81
81
  },
82
- "ff99-163": {
82
+ "497b-163": {
83
83
  "renderedLength": 181,
84
84
  "gzipLength": 129,
85
85
  "brotliLength": 0,
86
- "mainUid": "ff99-162"
86
+ "mainUid": "497b-162"
87
87
  },
88
- "ff99-165": {
88
+ "497b-165": {
89
89
  "renderedLength": 44,
90
90
  "gzipLength": 62,
91
91
  "brotliLength": 0,
92
- "mainUid": "ff99-164"
92
+ "mainUid": "497b-164"
93
93
  },
94
- "ff99-167": {
95
- "renderedLength": 64170,
96
- "gzipLength": 15197,
94
+ "497b-167": {
95
+ "renderedLength": 64443,
96
+ "gzipLength": 15232,
97
97
  "brotliLength": 0,
98
- "mainUid": "ff99-166"
98
+ "mainUid": "497b-166"
99
99
  },
100
- "ff99-169": {
100
+ "497b-169": {
101
101
  "renderedLength": 429,
102
102
  "gzipLength": 238,
103
103
  "brotliLength": 0,
104
- "mainUid": "ff99-168"
104
+ "mainUid": "497b-168"
105
105
  },
106
- "ff99-171": {
107
- "renderedLength": 17448,
108
- "gzipLength": 3863,
106
+ "497b-171": {
107
+ "renderedLength": 17084,
108
+ "gzipLength": 3790,
109
109
  "brotliLength": 0,
110
- "mainUid": "ff99-170"
110
+ "mainUid": "497b-170"
111
111
  },
112
- "ff99-173": {
112
+ "497b-173": {
113
113
  "renderedLength": 466,
114
114
  "gzipLength": 228,
115
115
  "brotliLength": 0,
116
- "mainUid": "ff99-172"
116
+ "mainUid": "497b-172"
117
117
  },
118
- "ff99-175": {
118
+ "497b-175": {
119
119
  "renderedLength": 641,
120
120
  "gzipLength": 305,
121
121
  "brotliLength": 0,
122
- "mainUid": "ff99-174"
122
+ "mainUid": "497b-174"
123
123
  },
124
- "ff99-177": {
124
+ "497b-177": {
125
125
  "renderedLength": 0,
126
126
  "gzipLength": 0,
127
127
  "brotliLength": 0,
128
- "mainUid": "ff99-176"
128
+ "mainUid": "497b-176"
129
129
  }
130
130
  },
131
131
  "nodeMetas": {
132
- "ff99-158": {
132
+ "497b-158": {
133
133
  "id": "/node_modules/.pnpm/@tanstack+store@0.0.1/node_modules/@tanstack/store/build/esm/index.js",
134
134
  "moduleParts": {
135
- "index.production.js": "ff99-159"
135
+ "index.production.js": "497b-159"
136
136
  },
137
137
  "imported": [],
138
138
  "importedBy": [
139
139
  {
140
- "uid": "ff99-160"
140
+ "uid": "497b-160"
141
141
  },
142
142
  {
143
- "uid": "ff99-166"
143
+ "uid": "497b-166"
144
144
  }
145
145
  ]
146
146
  },
147
- "ff99-160": {
147
+ "497b-160": {
148
148
  "id": "/node_modules/.pnpm/@tanstack+react-store@0.0.1/node_modules/@tanstack/react-store/build/esm/index.js",
149
149
  "moduleParts": {
150
- "index.production.js": "ff99-161"
150
+ "index.production.js": "497b-161"
151
151
  },
152
152
  "imported": [
153
153
  {
154
- "uid": "ff99-178"
154
+ "uid": "497b-178"
155
155
  },
156
156
  {
157
- "uid": "ff99-158"
157
+ "uid": "497b-158"
158
158
  }
159
159
  ],
160
160
  "importedBy": [
161
161
  {
162
- "uid": "ff99-176"
162
+ "uid": "497b-176"
163
163
  },
164
164
  {
165
- "uid": "ff99-170"
165
+ "uid": "497b-170"
166
166
  }
167
167
  ]
168
168
  },
169
- "ff99-162": {
169
+ "497b-162": {
170
170
  "id": "/node_modules/.pnpm/tiny-invariant@1.3.1/node_modules/tiny-invariant/dist/esm/tiny-invariant.js",
171
171
  "moduleParts": {
172
- "index.production.js": "ff99-163"
172
+ "index.production.js": "497b-163"
173
173
  },
174
174
  "imported": [],
175
175
  "importedBy": [
176
176
  {
177
- "uid": "ff99-166"
177
+ "uid": "497b-166"
178
178
  },
179
179
  {
180
- "uid": "ff99-170"
180
+ "uid": "497b-170"
181
181
  }
182
182
  ]
183
183
  },
184
- "ff99-164": {
184
+ "497b-164": {
185
185
  "id": "/node_modules/.pnpm/tiny-warning@1.0.3/node_modules/tiny-warning/dist/tiny-warning.esm.js",
186
186
  "moduleParts": {
187
- "index.production.js": "ff99-165"
187
+ "index.production.js": "497b-165"
188
188
  },
189
189
  "imported": [],
190
190
  "importedBy": [
191
191
  {
192
- "uid": "ff99-166"
192
+ "uid": "497b-166"
193
193
  },
194
194
  {
195
- "uid": "ff99-170"
195
+ "uid": "497b-170"
196
196
  }
197
197
  ]
198
198
  },
199
- "ff99-166": {
199
+ "497b-166": {
200
200
  "id": "/packages/router-core/build/esm/index.js",
201
201
  "moduleParts": {
202
- "index.production.js": "ff99-167"
202
+ "index.production.js": "497b-167"
203
203
  },
204
204
  "imported": [
205
205
  {
206
- "uid": "ff99-162"
206
+ "uid": "497b-162"
207
207
  },
208
208
  {
209
- "uid": "ff99-164"
209
+ "uid": "497b-164"
210
210
  },
211
211
  {
212
- "uid": "ff99-158"
212
+ "uid": "497b-158"
213
213
  }
214
214
  ],
215
215
  "importedBy": [
216
216
  {
217
- "uid": "ff99-176"
217
+ "uid": "497b-176"
218
218
  },
219
219
  {
220
- "uid": "ff99-170"
220
+ "uid": "497b-170"
221
221
  },
222
222
  {
223
- "uid": "ff99-172"
223
+ "uid": "497b-172"
224
224
  },
225
225
  {
226
- "uid": "ff99-174"
226
+ "uid": "497b-174"
227
227
  }
228
228
  ]
229
229
  },
230
- "ff99-168": {
230
+ "497b-168": {
231
231
  "id": "\u0000rollupPluginBabelHelpers.js",
232
232
  "moduleParts": {
233
- "index.production.js": "ff99-169"
233
+ "index.production.js": "497b-169"
234
234
  },
235
235
  "imported": [],
236
236
  "importedBy": [
237
237
  {
238
- "uid": "ff99-170"
238
+ "uid": "497b-170"
239
239
  }
240
240
  ]
241
241
  },
242
- "ff99-170": {
242
+ "497b-170": {
243
243
  "id": "/packages/react-router/src/react.tsx",
244
244
  "moduleParts": {
245
- "index.production.js": "ff99-171"
245
+ "index.production.js": "497b-171"
246
246
  },
247
247
  "imported": [
248
248
  {
249
- "uid": "ff99-168"
249
+ "uid": "497b-168"
250
250
  },
251
251
  {
252
- "uid": "ff99-179"
252
+ "uid": "497b-179"
253
253
  },
254
254
  {
255
- "uid": "ff99-160"
255
+ "uid": "497b-160"
256
256
  },
257
257
  {
258
- "uid": "ff99-162"
258
+ "uid": "497b-162"
259
259
  },
260
260
  {
261
- "uid": "ff99-164"
261
+ "uid": "497b-164"
262
262
  },
263
263
  {
264
- "uid": "ff99-166"
264
+ "uid": "497b-166"
265
265
  }
266
266
  ],
267
267
  "importedBy": [
268
268
  {
269
- "uid": "ff99-176"
269
+ "uid": "497b-176"
270
270
  },
271
271
  {
272
- "uid": "ff99-172"
272
+ "uid": "497b-172"
273
273
  },
274
274
  {
275
- "uid": "ff99-174"
275
+ "uid": "497b-174"
276
276
  }
277
277
  ]
278
278
  },
279
- "ff99-172": {
279
+ "497b-172": {
280
280
  "id": "/packages/react-router/src/scroll-restoration.tsx",
281
281
  "moduleParts": {
282
- "index.production.js": "ff99-173"
282
+ "index.production.js": "497b-173"
283
283
  },
284
284
  "imported": [
285
285
  {
286
- "uid": "ff99-179"
286
+ "uid": "497b-179"
287
287
  },
288
288
  {
289
- "uid": "ff99-166"
289
+ "uid": "497b-166"
290
290
  },
291
291
  {
292
- "uid": "ff99-170"
292
+ "uid": "497b-170"
293
293
  }
294
294
  ],
295
295
  "importedBy": [
296
296
  {
297
- "uid": "ff99-176"
297
+ "uid": "497b-176"
298
298
  }
299
299
  ]
300
300
  },
301
- "ff99-174": {
301
+ "497b-174": {
302
302
  "id": "/packages/react-router/src/awaited.tsx",
303
303
  "moduleParts": {
304
- "index.production.js": "ff99-175"
304
+ "index.production.js": "497b-175"
305
305
  },
306
306
  "imported": [
307
307
  {
308
- "uid": "ff99-166"
308
+ "uid": "497b-166"
309
309
  },
310
310
  {
311
- "uid": "ff99-170"
311
+ "uid": "497b-170"
312
312
  }
313
313
  ],
314
314
  "importedBy": [
315
315
  {
316
- "uid": "ff99-176"
316
+ "uid": "497b-176"
317
317
  }
318
318
  ]
319
319
  },
320
- "ff99-176": {
320
+ "497b-176": {
321
321
  "id": "/packages/react-router/src/index.tsx",
322
322
  "moduleParts": {
323
- "index.production.js": "ff99-177"
323
+ "index.production.js": "497b-177"
324
324
  },
325
325
  "imported": [
326
326
  {
327
- "uid": "ff99-160"
327
+ "uid": "497b-160"
328
328
  },
329
329
  {
330
- "uid": "ff99-166"
330
+ "uid": "497b-166"
331
331
  },
332
332
  {
333
- "uid": "ff99-170"
333
+ "uid": "497b-170"
334
334
  },
335
335
  {
336
- "uid": "ff99-172"
336
+ "uid": "497b-172"
337
337
  },
338
338
  {
339
- "uid": "ff99-174"
339
+ "uid": "497b-174"
340
340
  }
341
341
  ],
342
342
  "importedBy": [],
343
343
  "isEntry": true
344
344
  },
345
- "ff99-178": {
345
+ "497b-178": {
346
346
  "id": "use-sync-external-store/shim/with-selector",
347
347
  "moduleParts": {},
348
348
  "imported": [],
349
349
  "importedBy": [
350
350
  {
351
- "uid": "ff99-160"
351
+ "uid": "497b-160"
352
352
  }
353
353
  ],
354
354
  "isExternal": true
355
355
  },
356
- "ff99-179": {
356
+ "497b-179": {
357
357
  "id": "react",
358
358
  "moduleParts": {},
359
359
  "imported": [],
360
360
  "importedBy": [
361
361
  {
362
- "uid": "ff99-170"
362
+ "uid": "497b-170"
363
363
  },
364
364
  {
365
- "uid": "ff99-172"
365
+ "uid": "497b-172"
366
366
  }
367
367
  ],
368
368
  "isExternal": true
@@ -854,8 +854,6 @@
854
854
  const val = search[key];
855
855
  if (typeof val === 'undefined' || val === undefined) {
856
856
  delete search[key];
857
- } else if (Array.isArray(val)) {
858
- search[key] = val.map(stringifyValue);
859
857
  } else {
860
858
  search[key] = stringifyValue(val);
861
859
  }
@@ -906,6 +904,16 @@
906
904
  return next.matchesById[id];
907
905
  });
908
906
  }
907
+ if (matchesByIdChanged || matchesChanged || pendingMatchesChanged) {
908
+ const hasPendingComponent = next.pendingMatches.some(d => {
909
+ const route = this.getRoute(d.routeId);
910
+ return !!route?.options.pendingComponent;
911
+ });
912
+ next.renderedMatchIds = hasPendingComponent ? next.pendingMatchIds : next.matchIds;
913
+ next.renderedMatches = next.renderedMatchIds.map(id => {
914
+ return next.matchesById[id];
915
+ });
916
+ }
909
917
  next.isFetching = [...next.matches, ...next.pendingMatches].some(d => d.isFetching);
910
918
  this.state = next;
911
919
  },
@@ -1119,20 +1127,10 @@
1119
1127
  return this.latestLoadPromise;
1120
1128
  };
1121
1129
  #mergeMatches = (prevMatchesById, nextMatches) => {
1122
- const nextMatchesById = {
1123
- ...prevMatchesById
1130
+ return {
1131
+ ...prevMatchesById,
1132
+ ...Object.fromEntries(nextMatches.map(match => [match.id, match]))
1124
1133
  };
1125
- let hadNew = false;
1126
- nextMatches.forEach(match => {
1127
- if (!nextMatchesById[match.id]) {
1128
- hadNew = true;
1129
- nextMatchesById[match.id] = match;
1130
- }
1131
- });
1132
- if (!hadNew) {
1133
- return prevMatchesById;
1134
- }
1135
- return nextMatchesById;
1136
1134
  };
1137
1135
  getRoute = id => {
1138
1136
  const route = this.routesById[id];
@@ -1282,14 +1280,17 @@
1282
1280
  };
1283
1281
  try {
1284
1282
  const validator = typeof route.options.validateSearch === 'object' ? route.options.validateSearch.parse : route.options.validateSearch;
1285
- const routeSearch = validator?.(parentSearchInfo.search) ?? {};
1286
- const search = {
1283
+ let routeSearch = validator?.(parentSearchInfo.search) ?? {};
1284
+ let search = {
1287
1285
  ...parentSearchInfo.search,
1288
1286
  ...routeSearch
1289
1287
  };
1288
+ routeSearch = replaceEqualDeep(match.routeSearch, routeSearch);
1289
+ search = replaceEqualDeep(match.search, search);
1290
1290
  return {
1291
- routeSearch: replaceEqualDeep(match.routeSearch, routeSearch),
1292
- search: replaceEqualDeep(match.search, search)
1291
+ routeSearch,
1292
+ search,
1293
+ searchDidChange: match.routeSearch !== routeSearch
1293
1294
  };
1294
1295
  } catch (err) {
1295
1296
  match.searchError = new SearchParamError(err.message, {
@@ -1870,7 +1871,6 @@
1870
1871
  };
1871
1872
  #commitLocation = async location => {
1872
1873
  const next = this.buildNext(location);
1873
- const id = '' + Date.now() + Math.random();
1874
1874
  if (this.navigateTimeout) clearTimeout(this.navigateTimeout);
1875
1875
  let nextAction = 'replace';
1876
1876
  if (!location.replace) {
@@ -1881,10 +1881,7 @@
1881
1881
  nextAction = 'replace';
1882
1882
  }
1883
1883
  const href = `${next.pathname}${next.searchStr}${next.hash ? `#${next.hash}` : ''}`;
1884
- this.history[nextAction === 'push' ? 'push' : 'replace'](href, {
1885
- id,
1886
- ...next.state
1887
- });
1884
+ this.history[nextAction === 'push' ? 'push' : 'replace'](href, next.state);
1888
1885
  this.resetNextScroll = location.resetScroll ?? true;
1889
1886
  return this.latestLoadPromise;
1890
1887
  };
@@ -1970,6 +1967,8 @@
1970
1967
  pendingMatchIds: [],
1971
1968
  matches: [],
1972
1969
  pendingMatches: [],
1970
+ renderedMatchIds: [],
1971
+ renderedMatches: [],
1973
1972
  lastUpdated: Date.now()
1974
1973
  };
1975
1974
  }
@@ -2372,14 +2371,7 @@
2372
2371
  const router = useRouter();
2373
2372
  const matchIds = useRouterState({
2374
2373
  select: state => {
2375
- const hasPendingComponent = state.pendingMatches.some(d => {
2376
- const route = router.getRoute(d.routeId);
2377
- return !!route?.options.pendingComponent;
2378
- });
2379
- if (hasPendingComponent) {
2380
- return state.pendingMatchIds;
2381
- }
2382
- return state.matchIds;
2374
+ return state.renderedMatchIds;
2383
2375
  }
2384
2376
  });
2385
2377
  return /*#__PURE__*/React__namespace.createElement(matchIdsContext.Provider, {
@@ -2401,7 +2393,7 @@
2401
2393
  const matchIds = React__namespace.useContext(matchIdsContext);
2402
2394
  return useRouterState({
2403
2395
  select: state => {
2404
- const matches = state.matches.slice(state.matches.findIndex(d => d.id === matchIds[0]));
2396
+ const matches = state.renderedMatches.slice(state.renderedMatches.findIndex(d => d.id === matchIds[0]));
2405
2397
  return opts?.select ? opts.select(matches) : matches;
2406
2398
  }
2407
2399
  });
@@ -2412,8 +2404,7 @@
2412
2404
  const nearestMatchRouteId = router.getRouteMatch(nearestMatchId)?.routeId;
2413
2405
  const matchRouteId = useRouterState({
2414
2406
  select: state => {
2415
- const matches = state.status === 'pending' ? state.pendingMatches : state.matches;
2416
- const match = opts?.from ? matches.find(d => d.routeId === opts?.from) : matches.find(d => d.id === nearestMatchId);
2407
+ const match = opts?.from ? state.renderedMatches.find(d => d.routeId === opts?.from) : state.renderedMatches.find(d => d.id === nearestMatchId);
2417
2408
  return match.routeId;
2418
2409
  }
2419
2410
  });
@@ -2422,8 +2413,7 @@
2422
2413
  }
2423
2414
  const matchSelection = useRouterState({
2424
2415
  select: state => {
2425
- const matches = state.status === 'pending' ? state.pendingMatches : state.matches;
2426
- const match = opts?.from ? matches.find(d => d.routeId === opts?.from) : matches.find(d => d.id === nearestMatchId);
2416
+ const match = opts?.from ? state.renderedMatches.find(d => d.routeId === opts?.from) : state.renderedMatches.find(d => d.id === nearestMatchId);
2427
2417
  invariant(match, `Could not find ${opts?.from ? `an active match from "${opts.from}"` : 'a nearest match!'}`);
2428
2418
  return opts?.select ? opts.select(match) : match;
2429
2419
  }
@@ -2459,7 +2449,7 @@
2459
2449
  function useParams(opts) {
2460
2450
  return useRouterState({
2461
2451
  select: state => {
2462
- const params = last(state.matches)?.params;
2452
+ const params = last(state.renderedMatches)?.params;
2463
2453
  return opts?.select ? opts.select(params) : params;
2464
2454
  }
2465
2455
  });