@tanstack/react-router 0.0.1-beta.281 → 0.0.1-beta.283
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/build/cjs/Matches.js.map +1 -1
- package/build/cjs/link.js.map +1 -1
- package/build/cjs/router.js +36 -18
- package/build/cjs/router.js.map +1 -1
- package/build/esm/index.js +36 -18
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +351 -351
- package/build/types/Matches.d.ts +1 -0
- package/build/types/link.d.ts +1 -1
- package/build/types/router.d.ts +1 -0
- package/build/umd/index.development.js +36 -18
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +2 -2
- package/src/Matches.tsx +1 -0
- package/src/link.tsx +1 -1
- package/src/router.ts +47 -27
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.
|
|
4
|
+
"version": "0.0.1-beta.283",
|
|
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.
|
|
47
|
+
"@tanstack/history": "0.0.1-beta.283"
|
|
48
48
|
},
|
|
49
49
|
"scripts": {
|
|
50
50
|
"build": "rollup --config rollup.config.js"
|
package/src/Matches.tsx
CHANGED
package/src/link.tsx
CHANGED
|
@@ -178,7 +178,7 @@ export type SearchParamOptions<
|
|
|
178
178
|
>
|
|
179
179
|
>
|
|
180
180
|
>,
|
|
181
|
-
TFromSearchOptional = Omit<
|
|
181
|
+
TFromSearchOptional = Omit<FullSearchSchema<TRouteTree>, keyof TFromSearchEnsured>,
|
|
182
182
|
TFromSearch = Expand<TFromSearchEnsured & TFromSearchOptional>,
|
|
183
183
|
TToSearch = '' extends TTo
|
|
184
184
|
? FullSearchSchema<TRouteTree>
|
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
|
-
|
|
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.
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
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
|
) => {
|