@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
|
@@ -1379,12 +1379,10 @@ function createRouteMatch(router, route, opts) {
|
|
|
1379
1379
|
isPending: false,
|
|
1380
1380
|
isFetching: false,
|
|
1381
1381
|
isInvalid: false,
|
|
1382
|
+
invalidAt: Infinity,
|
|
1382
1383
|
getIsInvalid: () => {
|
|
1383
|
-
var _ref, _routeMatch$options$l;
|
|
1384
|
-
|
|
1385
1384
|
const now = Date.now();
|
|
1386
|
-
|
|
1387
|
-
return routeMatch.isInvalid || routeMatch.updatedAt + maxAge < now;
|
|
1385
|
+
return routeMatch.isInvalid || routeMatch.invalidAt < now;
|
|
1388
1386
|
},
|
|
1389
1387
|
__: {
|
|
1390
1388
|
abortController: new AbortController(),
|
|
@@ -1475,7 +1473,7 @@ function createRouteMatch(router, route, opts) {
|
|
|
1475
1473
|
hasLoaders: () => {
|
|
1476
1474
|
return !!(route.options.loader || route.options.import || elementTypes.some(d => typeof route.options[d] === 'function'));
|
|
1477
1475
|
},
|
|
1478
|
-
load: async
|
|
1476
|
+
load: async opts => {
|
|
1479
1477
|
const id = '' + Date.now() + Math.random();
|
|
1480
1478
|
routeMatch.__.latestId = id; // If the match was in an error state, set it
|
|
1481
1479
|
// to a loading state again. Otherwise, keep it
|
|
@@ -1530,6 +1528,8 @@ function createRouteMatch(router, route, opts) {
|
|
|
1530
1528
|
|
|
1531
1529
|
routeMatch.__.dataPromise = Promise.resolve().then(async () => {
|
|
1532
1530
|
try {
|
|
1531
|
+
var _ref, _ref2, _opts$maxAge;
|
|
1532
|
+
|
|
1533
1533
|
if (routeMatch.options.loader) {
|
|
1534
1534
|
const data = await routeMatch.options.loader({
|
|
1535
1535
|
params: routeMatch.params,
|
|
@@ -1547,6 +1547,7 @@ function createRouteMatch(router, route, opts) {
|
|
|
1547
1547
|
routeMatch.error = undefined;
|
|
1548
1548
|
routeMatch.status = 'success';
|
|
1549
1549
|
routeMatch.updatedAt = Date.now();
|
|
1550
|
+
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);
|
|
1550
1551
|
} catch (err) {
|
|
1551
1552
|
if (id !== routeMatch.__.latestId) {
|
|
1552
1553
|
return routeMatch.__.loaderPromise;
|
|
@@ -1669,7 +1670,8 @@ function createRouter(userOptions) {
|
|
|
1669
1670
|
const originalOptions = _extends({
|
|
1670
1671
|
defaultLoaderGcMaxAge: 5 * 60 * 1000,
|
|
1671
1672
|
defaultLoaderMaxAge: 0,
|
|
1672
|
-
|
|
1673
|
+
defaultPreloadMaxAge: 2000,
|
|
1674
|
+
defaultPreloadDelay: 50
|
|
1673
1675
|
}, userOptions, {
|
|
1674
1676
|
stringifySearch: (_userOptions$stringif = userOptions == null ? void 0 : userOptions.stringifySearch) != null ? _userOptions$stringif : defaultStringifySearch,
|
|
1675
1677
|
parseSearch: (_userOptions$parseSea = userOptions == null ? void 0 : userOptions.parseSearch) != null ? _userOptions$parseSea : defaultParseSearch
|
|
@@ -2066,7 +2068,21 @@ function createRouter(userOptions) {
|
|
|
2066
2068
|
delete router.matchCache[matchId];
|
|
2067
2069
|
});
|
|
2068
2070
|
},
|
|
2069
|
-
loadRoute: async function loadRoute(navigateOpts
|
|
2071
|
+
loadRoute: async function loadRoute(navigateOpts) {
|
|
2072
|
+
if (navigateOpts === void 0) {
|
|
2073
|
+
navigateOpts = router.location;
|
|
2074
|
+
}
|
|
2075
|
+
|
|
2076
|
+
const next = router.buildNext(navigateOpts);
|
|
2077
|
+
const matches = router.matchRoutes(next.pathname, {
|
|
2078
|
+
strictParseParams: true
|
|
2079
|
+
});
|
|
2080
|
+
await router.loadMatches(matches);
|
|
2081
|
+
return matches;
|
|
2082
|
+
},
|
|
2083
|
+
preloadRoute: async function preloadRoute(navigateOpts, loaderOpts) {
|
|
2084
|
+
var _ref4, _ref5, _loaderOpts$maxAge, _ref6, _ref7, _loaderOpts$gcMaxAge;
|
|
2085
|
+
|
|
2070
2086
|
if (navigateOpts === void 0) {
|
|
2071
2087
|
navigateOpts = router.location;
|
|
2072
2088
|
}
|
|
@@ -2077,7 +2093,8 @@ function createRouter(userOptions) {
|
|
|
2077
2093
|
});
|
|
2078
2094
|
await router.loadMatches(matches, {
|
|
2079
2095
|
preload: true,
|
|
2080
|
-
maxAge: loaderOpts.maxAge
|
|
2096
|
+
maxAge: (_ref4 = (_ref5 = (_loaderOpts$maxAge = loaderOpts.maxAge) != null ? _loaderOpts$maxAge : router.options.defaultPreloadMaxAge) != null ? _ref5 : router.options.defaultLoaderMaxAge) != null ? _ref4 : 0,
|
|
2097
|
+
gcMaxAge: (_ref6 = (_ref7 = (_loaderOpts$gcMaxAge = loaderOpts.gcMaxAge) != null ? _loaderOpts$gcMaxAge : router.options.defaultPreloadGcMaxAge) != null ? _ref7 : router.options.defaultLoaderGcMaxAge) != null ? _ref6 : 0
|
|
2081
2098
|
});
|
|
2082
2099
|
return matches;
|
|
2083
2100
|
},
|
|
@@ -2172,31 +2189,30 @@ function createRouter(userOptions) {
|
|
|
2172
2189
|
},
|
|
2173
2190
|
loadMatches: async (resolvedMatches, loaderOpts) => {
|
|
2174
2191
|
const now = Date.now();
|
|
2192
|
+
const minMaxAge = loaderOpts != null && loaderOpts.preload ? Math.max(loaderOpts == null ? void 0 : loaderOpts.maxAge, loaderOpts == null ? void 0 : loaderOpts.gcMaxAge) : 0;
|
|
2175
2193
|
const matchPromises = resolvedMatches.map(async match => {
|
|
2176
2194
|
// Validate the match (loads search params etc)
|
|
2177
|
-
match.__.validate(); //
|
|
2178
|
-
// if (!match.hasLoaders()) {
|
|
2179
|
-
// return
|
|
2180
|
-
// }
|
|
2181
|
-
// If this is a preload, add it to the preload cache
|
|
2195
|
+
match.__.validate(); // If this is a preload, add it to the preload cache
|
|
2182
2196
|
|
|
2183
2197
|
|
|
2184
|
-
if (loaderOpts != null && loaderOpts.preload &&
|
|
2198
|
+
if (loaderOpts != null && loaderOpts.preload && minMaxAge > 0) {
|
|
2185
2199
|
// If the match is currently active, don't preload it
|
|
2186
2200
|
if (router.state.matches.find(d => d.matchId === match.matchId)) {
|
|
2187
2201
|
return;
|
|
2188
2202
|
}
|
|
2189
2203
|
|
|
2190
2204
|
router.matchCache[match.matchId] = {
|
|
2191
|
-
gc: now + loaderOpts.
|
|
2192
|
-
// TODO: Should this use the route's maxAge?
|
|
2205
|
+
gc: now + loaderOpts.gcMaxAge,
|
|
2193
2206
|
match
|
|
2194
2207
|
};
|
|
2195
2208
|
} // If the match is invalid, errored or idle, trigger it to load
|
|
2196
2209
|
|
|
2197
2210
|
|
|
2198
2211
|
if (match.status === 'success' && match.getIsInvalid() || match.status === 'error' || match.status === 'idle') {
|
|
2199
|
-
|
|
2212
|
+
const maxAge = loaderOpts != null && loaderOpts.preload ? loaderOpts == null ? void 0 : loaderOpts.maxAge : undefined;
|
|
2213
|
+
match.load({
|
|
2214
|
+
maxAge
|
|
2215
|
+
});
|
|
2200
2216
|
}
|
|
2201
2217
|
|
|
2202
2218
|
if (match.status === 'loading') {
|
|
@@ -2258,7 +2274,7 @@ function createRouter(userOptions) {
|
|
|
2258
2274
|
const next = router.buildNext(location);
|
|
2259
2275
|
return router.commitLocation(next, location.replace);
|
|
2260
2276
|
},
|
|
2261
|
-
navigate: async
|
|
2277
|
+
navigate: async _ref8 => {
|
|
2262
2278
|
let {
|
|
2263
2279
|
from,
|
|
2264
2280
|
to = '.',
|
|
@@ -2266,7 +2282,7 @@ function createRouter(userOptions) {
|
|
|
2266
2282
|
hash,
|
|
2267
2283
|
replace,
|
|
2268
2284
|
params
|
|
2269
|
-
} =
|
|
2285
|
+
} = _ref8;
|
|
2270
2286
|
// If this link simply reloads the current route,
|
|
2271
2287
|
// make sure it has a new key so it will trigger a data refresh
|
|
2272
2288
|
// If this `to` is a valid external URL, return
|
|
@@ -2290,8 +2306,8 @@ function createRouter(userOptions) {
|
|
|
2290
2306
|
params
|
|
2291
2307
|
});
|
|
2292
2308
|
},
|
|
2293
|
-
buildLink:
|
|
2294
|
-
var _preload,
|
|
2309
|
+
buildLink: _ref9 => {
|
|
2310
|
+
var _preload, _ref10;
|
|
2295
2311
|
|
|
2296
2312
|
let {
|
|
2297
2313
|
from,
|
|
@@ -2304,9 +2320,10 @@ function createRouter(userOptions) {
|
|
|
2304
2320
|
activeOptions,
|
|
2305
2321
|
preload,
|
|
2306
2322
|
preloadMaxAge: userPreloadMaxAge,
|
|
2323
|
+
preloadGcMaxAge: userPreloadGcMaxAge,
|
|
2307
2324
|
preloadDelay: userPreloadDelay,
|
|
2308
2325
|
disabled
|
|
2309
|
-
} =
|
|
2326
|
+
} = _ref9;
|
|
2310
2327
|
|
|
2311
2328
|
// If this link simply reloads the current route,
|
|
2312
2329
|
// make sure it has a new key so it will trigger a data refresh
|
|
@@ -2329,9 +2346,8 @@ function createRouter(userOptions) {
|
|
|
2329
2346
|
replace
|
|
2330
2347
|
};
|
|
2331
2348
|
const next = router.buildNext(nextOpts);
|
|
2332
|
-
preload = (_preload = preload) != null ? _preload : router.options.
|
|
2333
|
-
const
|
|
2334
|
-
const preloadDelay = (_ref8 = userPreloadDelay != null ? userPreloadDelay : router.options.defaultLinkPreloadDelay) != null ? _ref8 : 0; // Compare path/hash for matches
|
|
2349
|
+
preload = (_preload = preload) != null ? _preload : router.options.defaultPreload;
|
|
2350
|
+
const preloadDelay = (_ref10 = userPreloadDelay != null ? userPreloadDelay : router.options.defaultPreloadDelay) != null ? _ref10 : 0; // Compare path/hash for matches
|
|
2335
2351
|
|
|
2336
2352
|
const pathIsEqual = router.state.location.pathname === next.pathname;
|
|
2337
2353
|
const currentPathSplit = router.state.location.pathname.split('/');
|
|
@@ -2359,9 +2375,10 @@ function createRouter(userOptions) {
|
|
|
2359
2375
|
|
|
2360
2376
|
|
|
2361
2377
|
const handleFocus = e => {
|
|
2362
|
-
if (preload
|
|
2363
|
-
router.
|
|
2364
|
-
maxAge:
|
|
2378
|
+
if (preload) {
|
|
2379
|
+
router.preloadRoute(nextOpts, {
|
|
2380
|
+
maxAge: userPreloadMaxAge,
|
|
2381
|
+
gcMaxAge: userPreloadGcMaxAge
|
|
2365
2382
|
});
|
|
2366
2383
|
}
|
|
2367
2384
|
};
|
|
@@ -2369,15 +2386,16 @@ function createRouter(userOptions) {
|
|
|
2369
2386
|
const handleEnter = e => {
|
|
2370
2387
|
const target = e.target || {};
|
|
2371
2388
|
|
|
2372
|
-
if (preload
|
|
2389
|
+
if (preload) {
|
|
2373
2390
|
if (target.preloadTimeout) {
|
|
2374
2391
|
return;
|
|
2375
2392
|
}
|
|
2376
2393
|
|
|
2377
2394
|
target.preloadTimeout = setTimeout(() => {
|
|
2378
2395
|
target.preloadTimeout = null;
|
|
2379
|
-
router.
|
|
2380
|
-
maxAge:
|
|
2396
|
+
router.preloadRoute(nextOpts, {
|
|
2397
|
+
maxAge: userPreloadMaxAge,
|
|
2398
|
+
gcMaxAge: userPreloadGcMaxAge
|
|
2381
2399
|
});
|
|
2382
2400
|
}, preloadDelay);
|
|
2383
2401
|
}
|