@tanstack/react-router 0.0.1-beta.282 → 0.0.1-beta.284

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tanstack/react-router",
3
3
  "author": "Tanner Linsley",
4
- "version": "0.0.1-beta.282",
4
+ "version": "0.0.1-beta.284",
5
5
  "license": "MIT",
6
6
  "repository": "tanstack/router",
7
7
  "homepage": "https://tanstack.com/router",
@@ -44,7 +44,7 @@
44
44
  "@tanstack/store": "^0.1.3",
45
45
  "tiny-invariant": "^1.3.1",
46
46
  "tiny-warning": "^1.0.3",
47
- "@tanstack/history": "0.0.1-beta.282"
47
+ "@tanstack/history": "0.0.1-beta.284"
48
48
  },
49
49
  "scripts": {
50
50
  "build": "rollup --config rollup.config.js"
package/src/Matches.tsx CHANGED
@@ -43,6 +43,7 @@ export interface RouteMatch<
43
43
  abortController: AbortController
44
44
  cause: 'preload' | 'enter' | 'stay'
45
45
  loaderDeps: RouteById<TRouteTree, TRouteId>['types']['loaderDeps']
46
+ preload: boolean
46
47
  invalid: boolean
47
48
  }
48
49
 
package/src/link.tsx CHANGED
@@ -178,7 +178,10 @@ export type SearchParamOptions<
178
178
  >
179
179
  >
180
180
  >,
181
- TFromSearchOptional = Omit<FullSearchSchema<TRouteTree>, keyof TFromSearchEnsured>,
181
+ TFromSearchOptional = Omit<
182
+ FullSearchSchema<TRouteTree>,
183
+ keyof TFromSearchEnsured
184
+ >,
182
185
  TFromSearch = Expand<TFromSearchEnsured & TFromSearchOptional>,
183
186
  TToSearch = '' extends TTo
184
187
  ? FullSearchSchema<TRouteTree>
@@ -207,15 +210,19 @@ export type PathParamOptions<
207
210
  TFromParamsOptional = Omit<AllParams<TRouteTree>, keyof TFromParamsEnsured>,
208
211
  TFromParams = Expand<TFromParamsOptional & TFromParamsEnsured>,
209
212
  TToParams = Expand<RouteByPath<TRouteTree, TTo>['types']['allParams']>,
210
- > = keyof PickRequired<TToParams> extends never
213
+ > = never extends TToParams
211
214
  ? {
212
- params?: true | ParamsReducer<TFromParams, TToParams>
213
- }
214
- : {
215
- params: TFromParamsEnsured extends PickRequired<TToParams>
216
- ? true | ParamsReducer<TFromParams, TToParams>
217
- : ParamsReducer<TFromParams, TToParams>
215
+ params?: true | ParamsReducer<Partial<TFromParams>, Partial<TFromParams>>
218
216
  }
217
+ : keyof PickRequired<TToParams> extends never
218
+ ? {
219
+ params?: true | ParamsReducer<TFromParams, TToParams>
220
+ }
221
+ : {
222
+ params: TFromParamsEnsured extends PickRequired<TToParams>
223
+ ? true | ParamsReducer<TFromParams, TToParams>
224
+ : ParamsReducer<TFromParams, TToParams>
225
+ }
219
226
 
220
227
  type ParamsReducer<TFrom, TTo> = TTo | ((current: TFrom) => TTo)
221
228
 
package/src/router.ts CHANGED
@@ -669,6 +669,7 @@ export class Router<
669
669
  cause,
670
670
  loaderDeps,
671
671
  invalid: false,
672
+ preload: false,
672
673
  }
673
674
 
674
675
  // Regardless of whether we're reusing an existing match or creating
@@ -1257,6 +1258,12 @@ export class Router<
1257
1258
  ? shouldReloadOption(loaderContext)
1258
1259
  : shouldReloadOption
1259
1260
 
1261
+ matches[index] = match = {
1262
+ ...match,
1263
+ preload:
1264
+ !!preload && !this.state.matches.find((d) => d.id === match.id),
1265
+ }
1266
+
1260
1267
  if (match.status !== 'success') {
1261
1268
  // If we need to potentially show the pending component,
1262
1269
  // start a timer to show it after the pendingMs
@@ -1328,23 +1335,7 @@ export class Router<
1328
1335
  const previousMatches = this.state.matches
1329
1336
 
1330
1337
  this.__store.batch(() => {
1331
- // This is where all of the garbage collection magic happens
1332
- this.__store.setState((s) => {
1333
- return {
1334
- ...s,
1335
- cachedMatches: s.cachedMatches.filter((d) => {
1336
- const route = this.looseRoutesById[d.routeId]!
1337
-
1338
- return (
1339
- d.status !== 'error' &&
1340
- Date.now() - d.updatedAt <
1341
- (route.options.gcTime ??
1342
- this.options.defaultGcTime ??
1343
- 5 * 60 * 1000)
1344
- )
1345
- }),
1346
- }
1347
- })
1338
+ this.cleanCache()
1348
1339
 
1349
1340
  // Match the routes
1350
1341
  pendingMatches = this.matchRoutes(next.pathname, next.search, {
@@ -1393,16 +1384,19 @@ export class Router<
1393
1384
 
1394
1385
  // Commit the pending matches. If a previous match was
1395
1386
  // removed, place it in the cachedMatches
1396
- this.__store.setState((s) => ({
1397
- ...s,
1398
- isLoading: false,
1399
- matches: pendingMatches,
1400
- pendingMatches: undefined,
1401
- cachedMatches: [
1402
- ...s.cachedMatches,
1403
- ...exitingMatches.filter((d) => d.status !== 'error'),
1404
- ],
1405
- }))
1387
+ this.__store.batch(() => {
1388
+ this.__store.setState((s) => ({
1389
+ ...s,
1390
+ isLoading: false,
1391
+ matches: s.pendingMatches!,
1392
+ pendingMatches: undefined,
1393
+ cachedMatches: [
1394
+ ...s.cachedMatches,
1395
+ ...exitingMatches.filter((d) => d.status !== 'error'),
1396
+ ],
1397
+ }))
1398
+ this.cleanCache()
1399
+ })
1406
1400
 
1407
1401
  //
1408
1402
  ;(
@@ -1440,6 +1434,32 @@ export class Router<
1440
1434
  return this.latestLoadPromise
1441
1435
  }
1442
1436
 
1437
+ cleanCache = () => {
1438
+ // This is where all of the garbage collection magic happens
1439
+ this.__store.setState((s) => {
1440
+ return {
1441
+ ...s,
1442
+ cachedMatches: s.cachedMatches.filter((d) => {
1443
+ const route = this.looseRoutesById[d.routeId]!
1444
+
1445
+ if (!route.options.loader) {
1446
+ return false
1447
+ }
1448
+
1449
+ // If the route was preloaded, use the preloadGcTime
1450
+ // otherwise, use the gcTime
1451
+ const gcTime =
1452
+ (d.preload
1453
+ ? route.options.preloadGcTime ?? this.options.defaultPreloadGcTime
1454
+ : route.options.gcTime ?? this.options.defaultGcTime) ??
1455
+ 5 * 60 * 1000
1456
+
1457
+ return d.status !== 'error' && Date.now() - d.updatedAt < gcTime
1458
+ }),
1459
+ }
1460
+ })
1461
+ }
1462
+
1443
1463
  preloadRoute = async (
1444
1464
  navigateOpts: ToOptions<TRouteTree> = this.state.location as any,
1445
1465
  ) => {