@tanstack/react-router 0.0.1-alpha.8 → 0.0.1-alpha.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.
- package/build/cjs/router-core/build/esm/index.js +49 -31
- package/build/cjs/router-core/build/esm/index.js.map +1 -1
- package/build/esm/index.js +49 -31
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +27 -27
- package/build/umd/index.development.js +49 -31
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +2 -2
- package/build/umd/index.production.js.map +1 -1
- package/package.json +2 -2
package/build/esm/index.js
CHANGED
|
@@ -1410,12 +1410,10 @@ function createRouteMatch(router, route, opts) {
|
|
|
1410
1410
|
isPending: false,
|
|
1411
1411
|
isFetching: false,
|
|
1412
1412
|
isInvalid: false,
|
|
1413
|
+
invalidAt: Infinity,
|
|
1413
1414
|
getIsInvalid: () => {
|
|
1414
|
-
var _ref, _routeMatch$options$l;
|
|
1415
|
-
|
|
1416
1415
|
const now = Date.now();
|
|
1417
|
-
|
|
1418
|
-
return routeMatch.isInvalid || routeMatch.updatedAt + maxAge < now;
|
|
1416
|
+
return routeMatch.isInvalid || routeMatch.invalidAt < now;
|
|
1419
1417
|
},
|
|
1420
1418
|
__: {
|
|
1421
1419
|
abortController: new AbortController(),
|
|
@@ -1506,7 +1504,7 @@ function createRouteMatch(router, route, opts) {
|
|
|
1506
1504
|
hasLoaders: () => {
|
|
1507
1505
|
return !!(route.options.loader || route.options.import || elementTypes.some(d => typeof route.options[d] === 'function'));
|
|
1508
1506
|
},
|
|
1509
|
-
load: async
|
|
1507
|
+
load: async opts => {
|
|
1510
1508
|
const id = '' + Date.now() + Math.random();
|
|
1511
1509
|
routeMatch.__.latestId = id; // If the match was in an error state, set it
|
|
1512
1510
|
// to a loading state again. Otherwise, keep it
|
|
@@ -1561,6 +1559,8 @@ function createRouteMatch(router, route, opts) {
|
|
|
1561
1559
|
|
|
1562
1560
|
routeMatch.__.dataPromise = Promise.resolve().then(async () => {
|
|
1563
1561
|
try {
|
|
1562
|
+
var _ref, _ref2, _opts$maxAge;
|
|
1563
|
+
|
|
1564
1564
|
if (routeMatch.options.loader) {
|
|
1565
1565
|
const data = await routeMatch.options.loader({
|
|
1566
1566
|
params: routeMatch.params,
|
|
@@ -1578,6 +1578,7 @@ function createRouteMatch(router, route, opts) {
|
|
|
1578
1578
|
routeMatch.error = undefined;
|
|
1579
1579
|
routeMatch.status = 'success';
|
|
1580
1580
|
routeMatch.updatedAt = Date.now();
|
|
1581
|
+
routeMatch.invalidAt = routeMatch.updatedAt + ((_ref = (_ref2 = (_opts$maxAge = opts == null ? void 0 : opts.maxAge) != null ? _opts$maxAge : routeMatch.options.loaderMaxAge) != null ? _ref2 : router.options.defaultLoaderMaxAge) != null ? _ref : 0);
|
|
1581
1582
|
} catch (err) {
|
|
1582
1583
|
if (id !== routeMatch.__.latestId) {
|
|
1583
1584
|
return routeMatch.__.loaderPromise;
|
|
@@ -1700,7 +1701,8 @@ function createRouter(userOptions) {
|
|
|
1700
1701
|
const originalOptions = _extends({
|
|
1701
1702
|
defaultLoaderGcMaxAge: 5 * 60 * 1000,
|
|
1702
1703
|
defaultLoaderMaxAge: 0,
|
|
1703
|
-
|
|
1704
|
+
defaultPreloadMaxAge: 2000,
|
|
1705
|
+
defaultPreloadDelay: 50
|
|
1704
1706
|
}, userOptions, {
|
|
1705
1707
|
stringifySearch: (_userOptions$stringif = userOptions == null ? void 0 : userOptions.stringifySearch) != null ? _userOptions$stringif : defaultStringifySearch,
|
|
1706
1708
|
parseSearch: (_userOptions$parseSea = userOptions == null ? void 0 : userOptions.parseSearch) != null ? _userOptions$parseSea : defaultParseSearch
|
|
@@ -2097,7 +2099,21 @@ function createRouter(userOptions) {
|
|
|
2097
2099
|
delete router.matchCache[matchId];
|
|
2098
2100
|
});
|
|
2099
2101
|
},
|
|
2100
|
-
loadRoute: async function loadRoute(navigateOpts
|
|
2102
|
+
loadRoute: async function loadRoute(navigateOpts) {
|
|
2103
|
+
if (navigateOpts === void 0) {
|
|
2104
|
+
navigateOpts = router.location;
|
|
2105
|
+
}
|
|
2106
|
+
|
|
2107
|
+
const next = router.buildNext(navigateOpts);
|
|
2108
|
+
const matches = router.matchRoutes(next.pathname, {
|
|
2109
|
+
strictParseParams: true
|
|
2110
|
+
});
|
|
2111
|
+
await router.loadMatches(matches);
|
|
2112
|
+
return matches;
|
|
2113
|
+
},
|
|
2114
|
+
preloadRoute: async function preloadRoute(navigateOpts, loaderOpts) {
|
|
2115
|
+
var _ref4, _ref5, _loaderOpts$maxAge, _ref6, _ref7, _loaderOpts$gcMaxAge;
|
|
2116
|
+
|
|
2101
2117
|
if (navigateOpts === void 0) {
|
|
2102
2118
|
navigateOpts = router.location;
|
|
2103
2119
|
}
|
|
@@ -2108,7 +2124,8 @@ function createRouter(userOptions) {
|
|
|
2108
2124
|
});
|
|
2109
2125
|
await router.loadMatches(matches, {
|
|
2110
2126
|
preload: true,
|
|
2111
|
-
maxAge: loaderOpts.maxAge
|
|
2127
|
+
maxAge: (_ref4 = (_ref5 = (_loaderOpts$maxAge = loaderOpts.maxAge) != null ? _loaderOpts$maxAge : router.options.defaultPreloadMaxAge) != null ? _ref5 : router.options.defaultLoaderMaxAge) != null ? _ref4 : 0,
|
|
2128
|
+
gcMaxAge: (_ref6 = (_ref7 = (_loaderOpts$gcMaxAge = loaderOpts.gcMaxAge) != null ? _loaderOpts$gcMaxAge : router.options.defaultPreloadGcMaxAge) != null ? _ref7 : router.options.defaultLoaderGcMaxAge) != null ? _ref6 : 0
|
|
2112
2129
|
});
|
|
2113
2130
|
return matches;
|
|
2114
2131
|
},
|
|
@@ -2203,31 +2220,30 @@ function createRouter(userOptions) {
|
|
|
2203
2220
|
},
|
|
2204
2221
|
loadMatches: async (resolvedMatches, loaderOpts) => {
|
|
2205
2222
|
const now = Date.now();
|
|
2223
|
+
const minMaxAge = loaderOpts != null && loaderOpts.preload ? Math.max(loaderOpts == null ? void 0 : loaderOpts.maxAge, loaderOpts == null ? void 0 : loaderOpts.gcMaxAge) : 0;
|
|
2206
2224
|
const matchPromises = resolvedMatches.map(async match => {
|
|
2207
2225
|
// Validate the match (loads search params etc)
|
|
2208
|
-
match.__.validate(); //
|
|
2209
|
-
// if (!match.hasLoaders()) {
|
|
2210
|
-
// return
|
|
2211
|
-
// }
|
|
2212
|
-
// If this is a preload, add it to the preload cache
|
|
2226
|
+
match.__.validate(); // If this is a preload, add it to the preload cache
|
|
2213
2227
|
|
|
2214
2228
|
|
|
2215
|
-
if (loaderOpts != null && loaderOpts.preload &&
|
|
2229
|
+
if (loaderOpts != null && loaderOpts.preload && minMaxAge > 0) {
|
|
2216
2230
|
// If the match is currently active, don't preload it
|
|
2217
2231
|
if (router.state.matches.find(d => d.matchId === match.matchId)) {
|
|
2218
2232
|
return;
|
|
2219
2233
|
}
|
|
2220
2234
|
|
|
2221
2235
|
router.matchCache[match.matchId] = {
|
|
2222
|
-
gc: now + loaderOpts.
|
|
2223
|
-
// TODO: Should this use the route's maxAge?
|
|
2236
|
+
gc: now + loaderOpts.gcMaxAge,
|
|
2224
2237
|
match
|
|
2225
2238
|
};
|
|
2226
2239
|
} // If the match is invalid, errored or idle, trigger it to load
|
|
2227
2240
|
|
|
2228
2241
|
|
|
2229
2242
|
if (match.status === 'success' && match.getIsInvalid() || match.status === 'error' || match.status === 'idle') {
|
|
2230
|
-
|
|
2243
|
+
const maxAge = loaderOpts != null && loaderOpts.preload ? loaderOpts == null ? void 0 : loaderOpts.maxAge : undefined;
|
|
2244
|
+
match.load({
|
|
2245
|
+
maxAge
|
|
2246
|
+
});
|
|
2231
2247
|
}
|
|
2232
2248
|
|
|
2233
2249
|
if (match.status === 'loading') {
|
|
@@ -2289,7 +2305,7 @@ function createRouter(userOptions) {
|
|
|
2289
2305
|
const next = router.buildNext(location);
|
|
2290
2306
|
return router.commitLocation(next, location.replace);
|
|
2291
2307
|
},
|
|
2292
|
-
navigate: async
|
|
2308
|
+
navigate: async _ref8 => {
|
|
2293
2309
|
let {
|
|
2294
2310
|
from,
|
|
2295
2311
|
to = '.',
|
|
@@ -2297,7 +2313,7 @@ function createRouter(userOptions) {
|
|
|
2297
2313
|
hash,
|
|
2298
2314
|
replace,
|
|
2299
2315
|
params
|
|
2300
|
-
} =
|
|
2316
|
+
} = _ref8;
|
|
2301
2317
|
// If this link simply reloads the current route,
|
|
2302
2318
|
// make sure it has a new key so it will trigger a data refresh
|
|
2303
2319
|
// If this `to` is a valid external URL, return
|
|
@@ -2321,8 +2337,8 @@ function createRouter(userOptions) {
|
|
|
2321
2337
|
params
|
|
2322
2338
|
});
|
|
2323
2339
|
},
|
|
2324
|
-
buildLink:
|
|
2325
|
-
var _preload,
|
|
2340
|
+
buildLink: _ref9 => {
|
|
2341
|
+
var _preload, _ref10;
|
|
2326
2342
|
|
|
2327
2343
|
let {
|
|
2328
2344
|
from,
|
|
@@ -2335,9 +2351,10 @@ function createRouter(userOptions) {
|
|
|
2335
2351
|
activeOptions,
|
|
2336
2352
|
preload,
|
|
2337
2353
|
preloadMaxAge: userPreloadMaxAge,
|
|
2354
|
+
preloadGcMaxAge: userPreloadGcMaxAge,
|
|
2338
2355
|
preloadDelay: userPreloadDelay,
|
|
2339
2356
|
disabled
|
|
2340
|
-
} =
|
|
2357
|
+
} = _ref9;
|
|
2341
2358
|
|
|
2342
2359
|
// If this link simply reloads the current route,
|
|
2343
2360
|
// make sure it has a new key so it will trigger a data refresh
|
|
@@ -2360,9 +2377,8 @@ function createRouter(userOptions) {
|
|
|
2360
2377
|
replace
|
|
2361
2378
|
};
|
|
2362
2379
|
const next = router.buildNext(nextOpts);
|
|
2363
|
-
preload = (_preload = preload) != null ? _preload : router.options.
|
|
2364
|
-
const
|
|
2365
|
-
const preloadDelay = (_ref8 = userPreloadDelay != null ? userPreloadDelay : router.options.defaultLinkPreloadDelay) != null ? _ref8 : 0; // Compare path/hash for matches
|
|
2380
|
+
preload = (_preload = preload) != null ? _preload : router.options.defaultPreload;
|
|
2381
|
+
const preloadDelay = (_ref10 = userPreloadDelay != null ? userPreloadDelay : router.options.defaultPreloadDelay) != null ? _ref10 : 0; // Compare path/hash for matches
|
|
2366
2382
|
|
|
2367
2383
|
const pathIsEqual = router.state.location.pathname === next.pathname;
|
|
2368
2384
|
const currentPathSplit = router.state.location.pathname.split('/');
|
|
@@ -2390,9 +2406,10 @@ function createRouter(userOptions) {
|
|
|
2390
2406
|
|
|
2391
2407
|
|
|
2392
2408
|
const handleFocus = e => {
|
|
2393
|
-
if (preload
|
|
2394
|
-
router.
|
|
2395
|
-
maxAge:
|
|
2409
|
+
if (preload) {
|
|
2410
|
+
router.preloadRoute(nextOpts, {
|
|
2411
|
+
maxAge: userPreloadMaxAge,
|
|
2412
|
+
gcMaxAge: userPreloadGcMaxAge
|
|
2396
2413
|
});
|
|
2397
2414
|
}
|
|
2398
2415
|
};
|
|
@@ -2400,15 +2417,16 @@ function createRouter(userOptions) {
|
|
|
2400
2417
|
const handleEnter = e => {
|
|
2401
2418
|
const target = e.target || {};
|
|
2402
2419
|
|
|
2403
|
-
if (preload
|
|
2420
|
+
if (preload) {
|
|
2404
2421
|
if (target.preloadTimeout) {
|
|
2405
2422
|
return;
|
|
2406
2423
|
}
|
|
2407
2424
|
|
|
2408
2425
|
target.preloadTimeout = setTimeout(() => {
|
|
2409
2426
|
target.preloadTimeout = null;
|
|
2410
|
-
router.
|
|
2411
|
-
maxAge:
|
|
2427
|
+
router.preloadRoute(nextOpts, {
|
|
2428
|
+
maxAge: userPreloadMaxAge,
|
|
2429
|
+
gcMaxAge: userPreloadGcMaxAge
|
|
2412
2430
|
});
|
|
2413
2431
|
}, preloadDelay);
|
|
2414
2432
|
}
|