@tanstack/router-core 0.0.1-beta.167 → 0.0.1-beta.169

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.
@@ -711,6 +711,7 @@ function stringifySearchWith(stringify, parser) {
711
711
  const componentTypes = ['component', 'errorComponent', 'pendingComponent'];
712
712
  class Router {
713
713
  #unsubHistory;
714
+ resetNextScroll = false;
714
715
  constructor(options) {
715
716
  this.options = {
716
717
  defaultPreloadDelay: 50,
@@ -1058,8 +1059,8 @@ class Router {
1058
1059
  params: routeParams,
1059
1060
  pathname: joinPaths([this.basepath, interpolatedPath]),
1060
1061
  updatedAt: Date.now(),
1061
- invalidAt: 9999999999999,
1062
- preloadInvalidAt: 9999999999999,
1062
+ invalidAt: Infinity,
1063
+ preloadInvalidAt: Infinity,
1063
1064
  routeSearch: {},
1064
1065
  search: {},
1065
1066
  status: hasLoaders ? 'pending' : 'success',
@@ -1142,7 +1143,6 @@ class Router {
1142
1143
  return matches;
1143
1144
  };
1144
1145
  loadMatches = async (resolvedMatches, opts) => {
1145
- this.cleanMatches();
1146
1146
  if (!opts?.preload) {
1147
1147
  resolvedMatches.forEach(match => {
1148
1148
  // Update each match with its latest route data
@@ -1155,10 +1155,12 @@ class Router {
1155
1155
  error: match.error,
1156
1156
  paramsError: match.paramsError,
1157
1157
  searchError: match.searchError,
1158
- params: match.params
1158
+ params: match.params,
1159
+ preloadInvalidAt: 0
1159
1160
  }));
1160
1161
  });
1161
1162
  }
1163
+ this.cleanMatches();
1162
1164
  let firstBadMatchIndex;
1163
1165
 
1164
1166
  // Check each match middleware to see if the route can be accessed
@@ -1294,6 +1296,7 @@ class Router {
1294
1296
  })());
1295
1297
  });
1296
1298
  await Promise.all(matchPromises);
1299
+ this.cleanMatches();
1297
1300
  };
1298
1301
  reload = () => {
1299
1302
  return this.navigate({
@@ -1311,7 +1314,8 @@ class Router {
1311
1314
  search,
1312
1315
  hash,
1313
1316
  replace,
1314
- params
1317
+ params,
1318
+ resetScroll
1315
1319
  }) => {
1316
1320
  // If this link simply reloads the current route,
1317
1321
  // make sure it has a new key so it will trigger a data refresh
@@ -1332,7 +1336,8 @@ class Router {
1332
1336
  search,
1333
1337
  hash,
1334
1338
  replace,
1335
- params
1339
+ params,
1340
+ resetScroll
1336
1341
  });
1337
1342
  };
1338
1343
  matchRoute = (location, opts) => {
@@ -1372,7 +1377,8 @@ class Router {
1372
1377
  preload,
1373
1378
  preloadDelay: userPreloadDelay,
1374
1379
  disabled,
1375
- state
1380
+ state,
1381
+ resetScroll
1376
1382
  }) => {
1377
1383
  // If this link simply reloads the current route,
1378
1384
  // make sure it has a new key so it will trigger a data refresh
@@ -1394,7 +1400,8 @@ class Router {
1394
1400
  params,
1395
1401
  hash,
1396
1402
  replace,
1397
- state
1403
+ state,
1404
+ resetScroll
1398
1405
  };
1399
1406
  const next = this.buildNext(nextOpts);
1400
1407
  preload = preload ?? this.options.defaultPreload;
@@ -1712,6 +1719,8 @@ class Router {
1712
1719
  id,
1713
1720
  ...next.state
1714
1721
  });
1722
+ this.resetNextScroll = location.resetScroll ?? true;
1723
+ console.log('resetScroll', this.resetNextScroll);
1715
1724
  return this.latestLoadPromise;
1716
1725
  };
1717
1726
  getRouteMatch = id => {
@@ -1737,7 +1746,7 @@ class Router {
1737
1746
  const route = this.getRoute(match.routeId);
1738
1747
  const updatedAt = opts?.updatedAt ?? Date.now();
1739
1748
  const preloadInvalidAt = updatedAt + (opts?.maxAge ?? route.options.preloadMaxAge ?? this.options.defaultPreloadMaxAge ?? 5000);
1740
- const invalidAt = updatedAt + (opts?.maxAge ?? route.options.maxAge ?? this.options.defaultMaxAge ?? 9999999999999);
1749
+ const invalidAt = updatedAt + (opts?.maxAge ?? route.options.maxAge ?? this.options.defaultMaxAge ?? Infinity);
1741
1750
  this.setRouteMatch(id, s => ({
1742
1751
  ...s,
1743
1752
  error: undefined,
@@ -1748,7 +1757,6 @@ class Router {
1748
1757
  preloadInvalidAt,
1749
1758
  invalidAt
1750
1759
  }));
1751
- if (this.state.matches.find(d => d.id === id)) ;
1752
1760
  };
1753
1761
  invalidate = async opts => {
1754
1762
  if (opts?.matchId) {
@@ -1931,6 +1939,9 @@ function watchScrollPositions(router, opts) {
1931
1939
  }
1932
1940
  function restoreScrollPositions(router, opts) {
1933
1941
  if (pathDidChange) {
1942
+ if (!router.resetNextScroll) {
1943
+ return;
1944
+ }
1934
1945
  const getKey = opts?.getKey || defaultGetKey;
1935
1946
  pathDidChange = false;
1936
1947
  const restoreKey = getKey(router.state.location);