@tanstack/react-router 0.0.1-alpha.7 → 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":"fe9b-59","name":"\u0000rollupPluginBabelHelpers.js"},{"name":"packages","children":[{"name":"router-core/build/esm/index.js","uid":"fe9b-61"},{"name":"react-router/src/index.tsx","uid":"fe9b-63"}]}]}],"isRoot":true},"nodeParts":{"fe9b-59":{"renderedLength":798,"gzipLength":366,"brotliLength":0,"mainUid":"fe9b-58"},"fe9b-61":{"renderedLength":73014,"gzipLength":15395,"brotliLength":0,"mainUid":"fe9b-60"},"fe9b-63":{"renderedLength":11495,"gzipLength":2999,"brotliLength":0,"mainUid":"fe9b-62"}},"nodeMetas":{"fe9b-58":{"id":"\u0000rollupPluginBabelHelpers.js","moduleParts":{"index.production.js":"fe9b-59"},"imported":[],"importedBy":[{"uid":"fe9b-62"}]},"fe9b-60":{"id":"/packages/router-core/build/esm/index.js","moduleParts":{"index.production.js":"fe9b-61"},"imported":[],"importedBy":[{"uid":"fe9b-62"}]},"fe9b-62":{"id":"/packages/react-router/src/index.tsx","moduleParts":{"index.production.js":"fe9b-63"},"imported":[{"uid":"fe9b-58"},{"uid":"fe9b-64"},{"uid":"fe9b-65"},{"uid":"fe9b-60"}],"importedBy":[],"isEntry":true},"fe9b-64":{"id":"react","moduleParts":{},"imported":[],"importedBy":[{"uid":"fe9b-62"}],"isExternal":true},"fe9b-65":{"id":"use-sync-external-store/shim","moduleParts":{},"imported":[],"importedBy":[{"uid":"fe9b-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": "fe9b-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": "fe9b-69"
18
+ "uid": "72d9-69"
19
19
  },
20
20
  {
21
21
  "name": "react-router/src/index.tsx",
22
- "uid": "fe9b-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
- "fe9b-67": {
32
+ "72d9-67": {
33
33
  "renderedLength": 798,
34
34
  "gzipLength": 366,
35
35
  "brotliLength": 0,
36
- "mainUid": "fe9b-66"
36
+ "mainUid": "72d9-66"
37
37
  },
38
- "fe9b-69": {
39
- "renderedLength": 73014,
40
- "gzipLength": 15395,
38
+ "72d9-69": {
39
+ "renderedLength": 74043,
40
+ "gzipLength": 15503,
41
41
  "brotliLength": 0,
42
- "mainUid": "fe9b-68"
42
+ "mainUid": "72d9-68"
43
43
  },
44
- "fe9b-71": {
44
+ "72d9-71": {
45
45
  "renderedLength": 11495,
46
46
  "gzipLength": 2999,
47
47
  "brotliLength": 0,
48
- "mainUid": "fe9b-70"
48
+ "mainUid": "72d9-70"
49
49
  }
50
50
  },
51
51
  "nodeMetas": {
52
- "fe9b-66": {
52
+ "72d9-66": {
53
53
  "id": "\u0000rollupPluginBabelHelpers.js",
54
54
  "moduleParts": {
55
- "index.production.js": "fe9b-67"
55
+ "index.production.js": "72d9-67"
56
56
  },
57
57
  "imported": [],
58
58
  "importedBy": [
59
59
  {
60
- "uid": "fe9b-70"
60
+ "uid": "72d9-70"
61
61
  }
62
62
  ]
63
63
  },
64
- "fe9b-68": {
64
+ "72d9-68": {
65
65
  "id": "/packages/router-core/build/esm/index.js",
66
66
  "moduleParts": {
67
- "index.production.js": "fe9b-69"
67
+ "index.production.js": "72d9-69"
68
68
  },
69
69
  "imported": [],
70
70
  "importedBy": [
71
71
  {
72
- "uid": "fe9b-70"
72
+ "uid": "72d9-70"
73
73
  }
74
74
  ]
75
75
  },
76
- "fe9b-70": {
76
+ "72d9-70": {
77
77
  "id": "/packages/react-router/src/index.tsx",
78
78
  "moduleParts": {
79
- "index.production.js": "fe9b-71"
79
+ "index.production.js": "72d9-71"
80
80
  },
81
81
  "imported": [
82
82
  {
83
- "uid": "fe9b-66"
83
+ "uid": "72d9-66"
84
84
  },
85
85
  {
86
- "uid": "fe9b-72"
86
+ "uid": "72d9-72"
87
87
  },
88
88
  {
89
- "uid": "fe9b-73"
89
+ "uid": "72d9-73"
90
90
  },
91
91
  {
92
- "uid": "fe9b-68"
92
+ "uid": "72d9-68"
93
93
  }
94
94
  ],
95
95
  "importedBy": [],
96
96
  "isEntry": true
97
97
  },
98
- "fe9b-72": {
98
+ "72d9-72": {
99
99
  "id": "react",
100
100
  "moduleParts": {},
101
101
  "imported": [],
102
102
  "importedBy": [
103
103
  {
104
- "uid": "fe9b-70"
104
+ "uid": "72d9-70"
105
105
  }
106
106
  ],
107
107
  "isExternal": true
108
108
  },
109
- "fe9b-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": "fe9b-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,32 +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
2242
+ match.__.validate(); // If this is a preload, add it to the preload cache
2225
2243
 
2226
2244
 
2227
- if (!match.hasLoaders()) {
2228
- return;
2229
- } // If this is a preload, add it to the preload cache
2230
-
2231
-
2232
- if (loaderOpts != null && loaderOpts.preload && (loaderOpts == null ? void 0 : loaderOpts.maxAge) > 0) {
2245
+ if (loaderOpts != null && loaderOpts.preload && minMaxAge > 0) {
2233
2246
  // If the match is currently active, don't preload it
2234
2247
  if (router.state.matches.find(d => d.matchId === match.matchId)) {
2235
2248
  return;
2236
2249
  }
2237
2250
 
2238
2251
  router.matchCache[match.matchId] = {
2239
- gc: now + loaderOpts.maxAge,
2240
- // TODO: Should this use the route's maxAge?
2252
+ gc: now + loaderOpts.gcMaxAge,
2241
2253
  match
2242
2254
  };
2243
2255
  } // If the match is invalid, errored or idle, trigger it to load
2244
2256
 
2245
2257
 
2246
2258
  if (match.status === 'success' && match.getIsInvalid() || match.status === 'error' || match.status === 'idle') {
2247
- match.load();
2259
+ const maxAge = loaderOpts != null && loaderOpts.preload ? loaderOpts == null ? void 0 : loaderOpts.maxAge : undefined;
2260
+ match.load({
2261
+ maxAge
2262
+ });
2248
2263
  }
2249
2264
 
2250
2265
  if (match.status === 'loading') {
@@ -2306,7 +2321,7 @@
2306
2321
  const next = router.buildNext(location);
2307
2322
  return router.commitLocation(next, location.replace);
2308
2323
  },
2309
- navigate: async _ref4 => {
2324
+ navigate: async _ref8 => {
2310
2325
  let {
2311
2326
  from,
2312
2327
  to = '.',
@@ -2314,7 +2329,7 @@
2314
2329
  hash,
2315
2330
  replace,
2316
2331
  params
2317
- } = _ref4;
2332
+ } = _ref8;
2318
2333
  // If this link simply reloads the current route,
2319
2334
  // make sure it has a new key so it will trigger a data refresh
2320
2335
  // If this `to` is a valid external URL, return
@@ -2338,8 +2353,8 @@
2338
2353
  params
2339
2354
  });
2340
2355
  },
2341
- buildLink: _ref5 => {
2342
- var _preload, _ref6, _ref7, _ref8;
2356
+ buildLink: _ref9 => {
2357
+ var _preload, _ref10;
2343
2358
 
2344
2359
  let {
2345
2360
  from,
@@ -2352,9 +2367,10 @@
2352
2367
  activeOptions,
2353
2368
  preload,
2354
2369
  preloadMaxAge: userPreloadMaxAge,
2370
+ preloadGcMaxAge: userPreloadGcMaxAge,
2355
2371
  preloadDelay: userPreloadDelay,
2356
2372
  disabled
2357
- } = _ref5;
2373
+ } = _ref9;
2358
2374
 
2359
2375
  // If this link simply reloads the current route,
2360
2376
  // make sure it has a new key so it will trigger a data refresh
@@ -2377,9 +2393,8 @@
2377
2393
  replace
2378
2394
  };
2379
2395
  const next = router.buildNext(nextOpts);
2380
- preload = (_preload = preload) != null ? _preload : router.options.defaultLinkPreload;
2381
- const preloadMaxAge = (_ref6 = (_ref7 = userPreloadMaxAge != null ? userPreloadMaxAge : router.options.defaultLinkPreloadMaxAge) != null ? _ref7 : router.options.defaultLoaderGcMaxAge) != null ? _ref6 : 0;
2382
- 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
2383
2398
 
2384
2399
  const pathIsEqual = router.state.location.pathname === next.pathname;
2385
2400
  const currentPathSplit = router.state.location.pathname.split('/');
@@ -2407,9 +2422,10 @@
2407
2422
 
2408
2423
 
2409
2424
  const handleFocus = e => {
2410
- if (preload && preloadMaxAge > 0) {
2411
- router.loadRoute(nextOpts, {
2412
- maxAge: preloadMaxAge
2425
+ if (preload) {
2426
+ router.preloadRoute(nextOpts, {
2427
+ maxAge: userPreloadMaxAge,
2428
+ gcMaxAge: userPreloadGcMaxAge
2413
2429
  });
2414
2430
  }
2415
2431
  };
@@ -2417,15 +2433,16 @@
2417
2433
  const handleEnter = e => {
2418
2434
  const target = e.target || {};
2419
2435
 
2420
- if (preload && preloadMaxAge > 0) {
2436
+ if (preload) {
2421
2437
  if (target.preloadTimeout) {
2422
2438
  return;
2423
2439
  }
2424
2440
 
2425
2441
  target.preloadTimeout = setTimeout(() => {
2426
2442
  target.preloadTimeout = null;
2427
- router.loadRoute(nextOpts, {
2428
- maxAge: preloadMaxAge
2443
+ router.preloadRoute(nextOpts, {
2444
+ maxAge: userPreloadMaxAge,
2445
+ gcMaxAge: userPreloadGcMaxAge
2429
2446
  });
2430
2447
  }, preloadDelay);
2431
2448
  }