@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.
@@ -4014,7 +4014,7 @@ var drawChart = (function (exports) {
4014
4014
  </script>
4015
4015
  <script>
4016
4016
  /*<!--*/
4017
- const data = {"version":2,"tree":{"name":"root","children":[{"name":"index.production.js","children":[{"uid":"065c-59","name":"\u0000rollupPluginBabelHelpers.js"},{"name":"packages","children":[{"name":"router-core/build/esm/index.js","uid":"065c-61"},{"name":"react-router/src/index.tsx","uid":"065c-63"}]}]}],"isRoot":true},"nodeParts":{"065c-59":{"renderedLength":798,"gzipLength":366,"brotliLength":0,"mainUid":"065c-58"},"065c-61":{"renderedLength":73033,"gzipLength":15403,"brotliLength":0,"mainUid":"065c-60"},"065c-63":{"renderedLength":11495,"gzipLength":2999,"brotliLength":0,"mainUid":"065c-62"}},"nodeMetas":{"065c-58":{"id":"\u0000rollupPluginBabelHelpers.js","moduleParts":{"index.production.js":"065c-59"},"imported":[],"importedBy":[{"uid":"065c-62"}]},"065c-60":{"id":"/packages/router-core/build/esm/index.js","moduleParts":{"index.production.js":"065c-61"},"imported":[],"importedBy":[{"uid":"065c-62"}]},"065c-62":{"id":"/packages/react-router/src/index.tsx","moduleParts":{"index.production.js":"065c-63"},"imported":[{"uid":"065c-58"},{"uid":"065c-64"},{"uid":"065c-65"},{"uid":"065c-60"}],"importedBy":[],"isEntry":true},"065c-64":{"id":"react","moduleParts":{},"imported":[],"importedBy":[{"uid":"065c-62"}],"isExternal":true},"065c-65":{"id":"use-sync-external-store/shim","moduleParts":{},"imported":[],"importedBy":[{"uid":"065c-62"}],"isExternal":true}},"env":{"rollup":"2.77.2"},"options":{"gzip":true,"brotli":false,"sourcemap":false}};
4017
+ const data = {"version":2,"tree":{"name":"root","children":[{"name":"index.production.js","children":[{"uid":"72d9-59","name":"\u0000rollupPluginBabelHelpers.js"},{"name":"packages","children":[{"name":"router-core/build/esm/index.js","uid":"72d9-61"},{"name":"react-router/src/index.tsx","uid":"72d9-63"}]}]}],"isRoot":true},"nodeParts":{"72d9-59":{"renderedLength":798,"gzipLength":366,"brotliLength":0,"mainUid":"72d9-58"},"72d9-61":{"renderedLength":74043,"gzipLength":15503,"brotliLength":0,"mainUid":"72d9-60"},"72d9-63":{"renderedLength":11495,"gzipLength":2999,"brotliLength":0,"mainUid":"72d9-62"}},"nodeMetas":{"72d9-58":{"id":"\u0000rollupPluginBabelHelpers.js","moduleParts":{"index.production.js":"72d9-59"},"imported":[],"importedBy":[{"uid":"72d9-62"}]},"72d9-60":{"id":"/packages/router-core/build/esm/index.js","moduleParts":{"index.production.js":"72d9-61"},"imported":[],"importedBy":[{"uid":"72d9-62"}]},"72d9-62":{"id":"/packages/react-router/src/index.tsx","moduleParts":{"index.production.js":"72d9-63"},"imported":[{"uid":"72d9-58"},{"uid":"72d9-64"},{"uid":"72d9-65"},{"uid":"72d9-60"}],"importedBy":[],"isEntry":true},"72d9-64":{"id":"react","moduleParts":{},"imported":[],"importedBy":[{"uid":"72d9-62"}],"isExternal":true},"72d9-65":{"id":"use-sync-external-store/shim","moduleParts":{},"imported":[],"importedBy":[{"uid":"72d9-62"}],"isExternal":true}},"env":{"rollup":"2.77.2"},"options":{"gzip":true,"brotli":false,"sourcemap":false}};
4018
4018
 
4019
4019
  const run = () => {
4020
4020
  const width = window.innerWidth;
@@ -7,7 +7,7 @@
7
7
  "name": "index.production.js",
8
8
  "children": [
9
9
  {
10
- "uid": "065c-67",
10
+ "uid": "72d9-67",
11
11
  "name": "\u0000rollupPluginBabelHelpers.js"
12
12
  },
13
13
  {
@@ -15,11 +15,11 @@
15
15
  "children": [
16
16
  {
17
17
  "name": "router-core/build/esm/index.js",
18
- "uid": "065c-69"
18
+ "uid": "72d9-69"
19
19
  },
20
20
  {
21
21
  "name": "react-router/src/index.tsx",
22
- "uid": "065c-71"
22
+ "uid": "72d9-71"
23
23
  }
24
24
  ]
25
25
  }
@@ -29,90 +29,90 @@
29
29
  "isRoot": true
30
30
  },
31
31
  "nodeParts": {
32
- "065c-67": {
32
+ "72d9-67": {
33
33
  "renderedLength": 798,
34
34
  "gzipLength": 366,
35
35
  "brotliLength": 0,
36
- "mainUid": "065c-66"
36
+ "mainUid": "72d9-66"
37
37
  },
38
- "065c-69": {
39
- "renderedLength": 73033,
40
- "gzipLength": 15403,
38
+ "72d9-69": {
39
+ "renderedLength": 74043,
40
+ "gzipLength": 15503,
41
41
  "brotliLength": 0,
42
- "mainUid": "065c-68"
42
+ "mainUid": "72d9-68"
43
43
  },
44
- "065c-71": {
44
+ "72d9-71": {
45
45
  "renderedLength": 11495,
46
46
  "gzipLength": 2999,
47
47
  "brotliLength": 0,
48
- "mainUid": "065c-70"
48
+ "mainUid": "72d9-70"
49
49
  }
50
50
  },
51
51
  "nodeMetas": {
52
- "065c-66": {
52
+ "72d9-66": {
53
53
  "id": "\u0000rollupPluginBabelHelpers.js",
54
54
  "moduleParts": {
55
- "index.production.js": "065c-67"
55
+ "index.production.js": "72d9-67"
56
56
  },
57
57
  "imported": [],
58
58
  "importedBy": [
59
59
  {
60
- "uid": "065c-70"
60
+ "uid": "72d9-70"
61
61
  }
62
62
  ]
63
63
  },
64
- "065c-68": {
64
+ "72d9-68": {
65
65
  "id": "/packages/router-core/build/esm/index.js",
66
66
  "moduleParts": {
67
- "index.production.js": "065c-69"
67
+ "index.production.js": "72d9-69"
68
68
  },
69
69
  "imported": [],
70
70
  "importedBy": [
71
71
  {
72
- "uid": "065c-70"
72
+ "uid": "72d9-70"
73
73
  }
74
74
  ]
75
75
  },
76
- "065c-70": {
76
+ "72d9-70": {
77
77
  "id": "/packages/react-router/src/index.tsx",
78
78
  "moduleParts": {
79
- "index.production.js": "065c-71"
79
+ "index.production.js": "72d9-71"
80
80
  },
81
81
  "imported": [
82
82
  {
83
- "uid": "065c-66"
83
+ "uid": "72d9-66"
84
84
  },
85
85
  {
86
- "uid": "065c-72"
86
+ "uid": "72d9-72"
87
87
  },
88
88
  {
89
- "uid": "065c-73"
89
+ "uid": "72d9-73"
90
90
  },
91
91
  {
92
- "uid": "065c-68"
92
+ "uid": "72d9-68"
93
93
  }
94
94
  ],
95
95
  "importedBy": [],
96
96
  "isEntry": true
97
97
  },
98
- "065c-72": {
98
+ "72d9-72": {
99
99
  "id": "react",
100
100
  "moduleParts": {},
101
101
  "imported": [],
102
102
  "importedBy": [
103
103
  {
104
- "uid": "065c-70"
104
+ "uid": "72d9-70"
105
105
  }
106
106
  ],
107
107
  "isExternal": true
108
108
  },
109
- "065c-73": {
109
+ "72d9-73": {
110
110
  "id": "use-sync-external-store/shim",
111
111
  "moduleParts": {},
112
112
  "imported": [],
113
113
  "importedBy": [
114
114
  {
115
- "uid": "065c-70"
115
+ "uid": "72d9-70"
116
116
  }
117
117
  ],
118
118
  "isExternal": true
@@ -1426,12 +1426,10 @@
1426
1426
  isPending: false,
1427
1427
  isFetching: false,
1428
1428
  isInvalid: false,
1429
+ invalidAt: Infinity,
1429
1430
  getIsInvalid: () => {
1430
- var _ref, _routeMatch$options$l;
1431
-
1432
1431
  const now = Date.now();
1433
- const maxAge = (_ref = (_routeMatch$options$l = routeMatch.options.loaderMaxAge) != null ? _routeMatch$options$l : router.options.defaultLoaderMaxAge) != null ? _ref : 0;
1434
- return routeMatch.isInvalid || routeMatch.updatedAt + maxAge < now;
1432
+ return routeMatch.isInvalid || routeMatch.invalidAt < now;
1435
1433
  },
1436
1434
  __: {
1437
1435
  abortController: new AbortController(),
@@ -1522,7 +1520,7 @@
1522
1520
  hasLoaders: () => {
1523
1521
  return !!(route.options.loader || route.options.import || elementTypes.some(d => typeof route.options[d] === 'function'));
1524
1522
  },
1525
- load: async () => {
1523
+ load: async opts => {
1526
1524
  const id = '' + Date.now() + Math.random();
1527
1525
  routeMatch.__.latestId = id; // If the match was in an error state, set it
1528
1526
  // to a loading state again. Otherwise, keep it
@@ -1577,6 +1575,8 @@
1577
1575
 
1578
1576
  routeMatch.__.dataPromise = Promise.resolve().then(async () => {
1579
1577
  try {
1578
+ var _ref, _ref2, _opts$maxAge;
1579
+
1580
1580
  if (routeMatch.options.loader) {
1581
1581
  const data = await routeMatch.options.loader({
1582
1582
  params: routeMatch.params,
@@ -1594,6 +1594,7 @@
1594
1594
  routeMatch.error = undefined;
1595
1595
  routeMatch.status = 'success';
1596
1596
  routeMatch.updatedAt = Date.now();
1597
+ 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);
1597
1598
  } catch (err) {
1598
1599
  if (id !== routeMatch.__.latestId) {
1599
1600
  return routeMatch.__.loaderPromise;
@@ -1716,7 +1717,8 @@
1716
1717
  const originalOptions = _extends({
1717
1718
  defaultLoaderGcMaxAge: 5 * 60 * 1000,
1718
1719
  defaultLoaderMaxAge: 0,
1719
- defaultLinkPreloadDelay: 50
1720
+ defaultPreloadMaxAge: 2000,
1721
+ defaultPreloadDelay: 50
1720
1722
  }, userOptions, {
1721
1723
  stringifySearch: (_userOptions$stringif = userOptions == null ? void 0 : userOptions.stringifySearch) != null ? _userOptions$stringif : defaultStringifySearch,
1722
1724
  parseSearch: (_userOptions$parseSea = userOptions == null ? void 0 : userOptions.parseSearch) != null ? _userOptions$parseSea : defaultParseSearch
@@ -2113,7 +2115,21 @@
2113
2115
  delete router.matchCache[matchId];
2114
2116
  });
2115
2117
  },
2116
- loadRoute: async function loadRoute(navigateOpts, loaderOpts) {
2118
+ loadRoute: async function loadRoute(navigateOpts) {
2119
+ if (navigateOpts === void 0) {
2120
+ navigateOpts = router.location;
2121
+ }
2122
+
2123
+ const next = router.buildNext(navigateOpts);
2124
+ const matches = router.matchRoutes(next.pathname, {
2125
+ strictParseParams: true
2126
+ });
2127
+ await router.loadMatches(matches);
2128
+ return matches;
2129
+ },
2130
+ preloadRoute: async function preloadRoute(navigateOpts, loaderOpts) {
2131
+ var _ref4, _ref5, _loaderOpts$maxAge, _ref6, _ref7, _loaderOpts$gcMaxAge;
2132
+
2117
2133
  if (navigateOpts === void 0) {
2118
2134
  navigateOpts = router.location;
2119
2135
  }
@@ -2124,7 +2140,8 @@
2124
2140
  });
2125
2141
  await router.loadMatches(matches, {
2126
2142
  preload: true,
2127
- maxAge: loaderOpts.maxAge
2143
+ maxAge: (_ref4 = (_ref5 = (_loaderOpts$maxAge = loaderOpts.maxAge) != null ? _loaderOpts$maxAge : router.options.defaultPreloadMaxAge) != null ? _ref5 : router.options.defaultLoaderMaxAge) != null ? _ref4 : 0,
2144
+ gcMaxAge: (_ref6 = (_ref7 = (_loaderOpts$gcMaxAge = loaderOpts.gcMaxAge) != null ? _loaderOpts$gcMaxAge : router.options.defaultPreloadGcMaxAge) != null ? _ref7 : router.options.defaultLoaderGcMaxAge) != null ? _ref6 : 0
2128
2145
  });
2129
2146
  return matches;
2130
2147
  },
@@ -2219,31 +2236,30 @@
2219
2236
  },
2220
2237
  loadMatches: async (resolvedMatches, loaderOpts) => {
2221
2238
  const now = Date.now();
2239
+ const minMaxAge = loaderOpts != null && loaderOpts.preload ? Math.max(loaderOpts == null ? void 0 : loaderOpts.maxAge, loaderOpts == null ? void 0 : loaderOpts.gcMaxAge) : 0;
2222
2240
  const matchPromises = resolvedMatches.map(async match => {
2223
2241
  // Validate the match (loads search params etc)
2224
- match.__.validate(); // // If the match doesn't have a loader, don't attempt to load it
2225
- // if (!match.hasLoaders()) {
2226
- // return
2227
- // }
2228
- // If this is a preload, add it to the preload cache
2242
+ match.__.validate(); // If this is a preload, add it to the preload cache
2229
2243
 
2230
2244
 
2231
- if (loaderOpts != null && loaderOpts.preload && (loaderOpts == null ? void 0 : loaderOpts.maxAge) > 0) {
2245
+ if (loaderOpts != null && loaderOpts.preload && minMaxAge > 0) {
2232
2246
  // If the match is currently active, don't preload it
2233
2247
  if (router.state.matches.find(d => d.matchId === match.matchId)) {
2234
2248
  return;
2235
2249
  }
2236
2250
 
2237
2251
  router.matchCache[match.matchId] = {
2238
- gc: now + loaderOpts.maxAge,
2239
- // TODO: Should this use the route's maxAge?
2252
+ gc: now + loaderOpts.gcMaxAge,
2240
2253
  match
2241
2254
  };
2242
2255
  } // If the match is invalid, errored or idle, trigger it to load
2243
2256
 
2244
2257
 
2245
2258
  if (match.status === 'success' && match.getIsInvalid() || match.status === 'error' || match.status === 'idle') {
2246
- match.load();
2259
+ const maxAge = loaderOpts != null && loaderOpts.preload ? loaderOpts == null ? void 0 : loaderOpts.maxAge : undefined;
2260
+ match.load({
2261
+ maxAge
2262
+ });
2247
2263
  }
2248
2264
 
2249
2265
  if (match.status === 'loading') {
@@ -2305,7 +2321,7 @@
2305
2321
  const next = router.buildNext(location);
2306
2322
  return router.commitLocation(next, location.replace);
2307
2323
  },
2308
- navigate: async _ref4 => {
2324
+ navigate: async _ref8 => {
2309
2325
  let {
2310
2326
  from,
2311
2327
  to = '.',
@@ -2313,7 +2329,7 @@
2313
2329
  hash,
2314
2330
  replace,
2315
2331
  params
2316
- } = _ref4;
2332
+ } = _ref8;
2317
2333
  // If this link simply reloads the current route,
2318
2334
  // make sure it has a new key so it will trigger a data refresh
2319
2335
  // If this `to` is a valid external URL, return
@@ -2337,8 +2353,8 @@
2337
2353
  params
2338
2354
  });
2339
2355
  },
2340
- buildLink: _ref5 => {
2341
- var _preload, _ref6, _ref7, _ref8;
2356
+ buildLink: _ref9 => {
2357
+ var _preload, _ref10;
2342
2358
 
2343
2359
  let {
2344
2360
  from,
@@ -2351,9 +2367,10 @@
2351
2367
  activeOptions,
2352
2368
  preload,
2353
2369
  preloadMaxAge: userPreloadMaxAge,
2370
+ preloadGcMaxAge: userPreloadGcMaxAge,
2354
2371
  preloadDelay: userPreloadDelay,
2355
2372
  disabled
2356
- } = _ref5;
2373
+ } = _ref9;
2357
2374
 
2358
2375
  // If this link simply reloads the current route,
2359
2376
  // make sure it has a new key so it will trigger a data refresh
@@ -2376,9 +2393,8 @@
2376
2393
  replace
2377
2394
  };
2378
2395
  const next = router.buildNext(nextOpts);
2379
- preload = (_preload = preload) != null ? _preload : router.options.defaultLinkPreload;
2380
- const preloadMaxAge = (_ref6 = (_ref7 = userPreloadMaxAge != null ? userPreloadMaxAge : router.options.defaultLinkPreloadMaxAge) != null ? _ref7 : router.options.defaultLoaderGcMaxAge) != null ? _ref6 : 0;
2381
- const preloadDelay = (_ref8 = userPreloadDelay != null ? userPreloadDelay : router.options.defaultLinkPreloadDelay) != null ? _ref8 : 0; // Compare path/hash for matches
2396
+ preload = (_preload = preload) != null ? _preload : router.options.defaultPreload;
2397
+ const preloadDelay = (_ref10 = userPreloadDelay != null ? userPreloadDelay : router.options.defaultPreloadDelay) != null ? _ref10 : 0; // Compare path/hash for matches
2382
2398
 
2383
2399
  const pathIsEqual = router.state.location.pathname === next.pathname;
2384
2400
  const currentPathSplit = router.state.location.pathname.split('/');
@@ -2406,9 +2422,10 @@
2406
2422
 
2407
2423
 
2408
2424
  const handleFocus = e => {
2409
- if (preload && preloadMaxAge > 0) {
2410
- router.loadRoute(nextOpts, {
2411
- maxAge: preloadMaxAge
2425
+ if (preload) {
2426
+ router.preloadRoute(nextOpts, {
2427
+ maxAge: userPreloadMaxAge,
2428
+ gcMaxAge: userPreloadGcMaxAge
2412
2429
  });
2413
2430
  }
2414
2431
  };
@@ -2416,15 +2433,16 @@
2416
2433
  const handleEnter = e => {
2417
2434
  const target = e.target || {};
2418
2435
 
2419
- if (preload && preloadMaxAge > 0) {
2436
+ if (preload) {
2420
2437
  if (target.preloadTimeout) {
2421
2438
  return;
2422
2439
  }
2423
2440
 
2424
2441
  target.preloadTimeout = setTimeout(() => {
2425
2442
  target.preloadTimeout = null;
2426
- router.loadRoute(nextOpts, {
2427
- maxAge: preloadMaxAge
2443
+ router.preloadRoute(nextOpts, {
2444
+ maxAge: userPreloadMaxAge,
2445
+ gcMaxAge: userPreloadGcMaxAge
2428
2446
  });
2429
2447
  }, preloadDelay);
2430
2448
  }