@tanstack/react-router 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.
@@ -9,10 +9,10 @@
9
9
  * @license MIT
10
10
  */
11
11
  (function (global, factory) {
12
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react'), require('use-sync-external-store/shim/with-selector')) :
13
- typeof define === 'function' && define.amd ? define(['exports', 'react', 'use-sync-external-store/shim/with-selector'], factory) :
14
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ReactRouter = {}, global.React, global.withSelector));
15
- })(this, (function (exports, React, withSelector) { 'use strict';
12
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('use-sync-external-store/shim/with-selector'), require('react')) :
13
+ typeof define === 'function' && define.amd ? define(['exports', 'use-sync-external-store/shim/with-selector', 'react'], factory) :
14
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ReactRouter = {}, global.withSelector, global.React));
15
+ })(this, (function (exports, withSelector, React) { 'use strict';
16
16
 
17
17
  function _interopNamespace(e) {
18
18
  if (e && e.__esModule) return e;
@@ -34,21 +34,6 @@
34
34
 
35
35
  var React__namespace = /*#__PURE__*/_interopNamespace(React);
36
36
 
37
- function _extends() {
38
- _extends = Object.assign ? Object.assign.bind() : function (target) {
39
- for (var i = 1; i < arguments.length; i++) {
40
- var source = arguments[i];
41
- for (var key in source) {
42
- if (Object.prototype.hasOwnProperty.call(source, key)) {
43
- target[key] = source[key];
44
- }
45
- }
46
- }
47
- return target;
48
- };
49
- return _extends.apply(this, arguments);
50
- }
51
-
52
37
  /**
53
38
  * @tanstack/store/src/index.ts
54
39
  *
@@ -886,6 +871,7 @@
886
871
  const componentTypes = ['component', 'errorComponent', 'pendingComponent'];
887
872
  class Router {
888
873
  #unsubHistory;
874
+ resetNextScroll = false;
889
875
  constructor(options) {
890
876
  this.options = {
891
877
  defaultPreloadDelay: 50,
@@ -1233,8 +1219,8 @@
1233
1219
  params: routeParams,
1234
1220
  pathname: joinPaths([this.basepath, interpolatedPath]),
1235
1221
  updatedAt: Date.now(),
1236
- invalidAt: 9999999999999,
1237
- preloadInvalidAt: 9999999999999,
1222
+ invalidAt: Infinity,
1223
+ preloadInvalidAt: Infinity,
1238
1224
  routeSearch: {},
1239
1225
  search: {},
1240
1226
  status: hasLoaders ? 'pending' : 'success',
@@ -1317,7 +1303,6 @@
1317
1303
  return matches;
1318
1304
  };
1319
1305
  loadMatches = async (resolvedMatches, opts) => {
1320
- this.cleanMatches();
1321
1306
  if (!opts?.preload) {
1322
1307
  resolvedMatches.forEach(match => {
1323
1308
  // Update each match with its latest route data
@@ -1330,10 +1315,12 @@
1330
1315
  error: match.error,
1331
1316
  paramsError: match.paramsError,
1332
1317
  searchError: match.searchError,
1333
- params: match.params
1318
+ params: match.params,
1319
+ preloadInvalidAt: 0
1334
1320
  }));
1335
1321
  });
1336
1322
  }
1323
+ this.cleanMatches();
1337
1324
  let firstBadMatchIndex;
1338
1325
 
1339
1326
  // Check each match middleware to see if the route can be accessed
@@ -1469,6 +1456,7 @@
1469
1456
  })());
1470
1457
  });
1471
1458
  await Promise.all(matchPromises);
1459
+ this.cleanMatches();
1472
1460
  };
1473
1461
  reload = () => {
1474
1462
  return this.navigate({
@@ -1486,7 +1474,8 @@
1486
1474
  search,
1487
1475
  hash,
1488
1476
  replace,
1489
- params
1477
+ params,
1478
+ resetScroll
1490
1479
  }) => {
1491
1480
  // If this link simply reloads the current route,
1492
1481
  // make sure it has a new key so it will trigger a data refresh
@@ -1507,7 +1496,8 @@
1507
1496
  search,
1508
1497
  hash,
1509
1498
  replace,
1510
- params
1499
+ params,
1500
+ resetScroll
1511
1501
  });
1512
1502
  };
1513
1503
  matchRoute = (location, opts) => {
@@ -1547,7 +1537,8 @@
1547
1537
  preload,
1548
1538
  preloadDelay: userPreloadDelay,
1549
1539
  disabled,
1550
- state
1540
+ state,
1541
+ resetScroll
1551
1542
  }) => {
1552
1543
  // If this link simply reloads the current route,
1553
1544
  // make sure it has a new key so it will trigger a data refresh
@@ -1569,7 +1560,8 @@
1569
1560
  params,
1570
1561
  hash,
1571
1562
  replace,
1572
- state
1563
+ state,
1564
+ resetScroll
1573
1565
  };
1574
1566
  const next = this.buildNext(nextOpts);
1575
1567
  preload = preload ?? this.options.defaultPreload;
@@ -1887,6 +1879,8 @@
1887
1879
  id,
1888
1880
  ...next.state
1889
1881
  });
1882
+ this.resetNextScroll = location.resetScroll ?? true;
1883
+ console.log('resetScroll', this.resetNextScroll);
1890
1884
  return this.latestLoadPromise;
1891
1885
  };
1892
1886
  getRouteMatch = id => {
@@ -1912,7 +1906,7 @@
1912
1906
  const route = this.getRoute(match.routeId);
1913
1907
  const updatedAt = opts?.updatedAt ?? Date.now();
1914
1908
  const preloadInvalidAt = updatedAt + (opts?.maxAge ?? route.options.preloadMaxAge ?? this.options.defaultPreloadMaxAge ?? 5000);
1915
- const invalidAt = updatedAt + (opts?.maxAge ?? route.options.maxAge ?? this.options.defaultMaxAge ?? 9999999999999);
1909
+ const invalidAt = updatedAt + (opts?.maxAge ?? route.options.maxAge ?? this.options.defaultMaxAge ?? Infinity);
1916
1910
  this.setRouteMatch(id, s => ({
1917
1911
  ...s,
1918
1912
  error: undefined,
@@ -1923,7 +1917,6 @@
1923
1917
  preloadInvalidAt,
1924
1918
  invalidAt
1925
1919
  }));
1926
- if (this.state.matches.find(d => d.id === id)) ;
1927
1920
  };
1928
1921
  invalidate = async opts => {
1929
1922
  if (opts?.matchId) {
@@ -2106,6 +2099,9 @@
2106
2099
  }
2107
2100
  function restoreScrollPositions(router, opts) {
2108
2101
  if (pathDidChange) {
2102
+ if (!router.resetNextScroll) {
2103
+ return;
2104
+ }
2109
2105
  const getKey = opts?.getKey || defaultGetKey;
2110
2106
  pathDidChange = false;
2111
2107
  const restoreKey = getKey(router.state.location);
@@ -2154,44 +2150,19 @@
2154
2150
  return typeof obj === 'object' && obj !== null && !(obj instanceof Promise) && !obj.then && '__deferredState' in obj;
2155
2151
  }
2156
2152
 
2157
- const useLayoutEffect = typeof window !== 'undefined' ? React__namespace.useLayoutEffect : React__namespace.useEffect;
2158
- function useScrollRestoration(options) {
2159
- const router = useRouter();
2160
- useLayoutEffect(() => {
2161
- return watchScrollPositions(router, options);
2162
- }, []);
2163
- useLayoutEffect(() => {
2164
- restoreScrollPositions(router, options);
2165
- });
2166
- }
2167
- function ScrollRestoration(props) {
2168
- useScrollRestoration(props);
2169
- return null;
2170
- }
2171
-
2172
- function useDeferred({
2173
- promise
2174
- }) {
2175
- const router = useRouter();
2176
- let state = promise.__deferredState;
2177
- const key = `__TSR__DEFERRED__${state.uid}`;
2178
- if (isDehydratedDeferred(promise)) {
2179
- state = router.hydrateData(key);
2180
- promise = Promise.resolve(state.data);
2181
- promise.__deferredState = state;
2182
- }
2183
- if (state.status === 'pending') {
2184
- throw promise;
2185
- }
2186
- if (state.status === 'error') {
2187
- throw state.error;
2188
- }
2189
- router.dehydrateData(key, state);
2190
- return [state.data];
2191
- }
2192
- function Deferred(props) {
2193
- const awaited = useDeferred(props);
2194
- return props.children(...awaited);
2153
+ function _extends() {
2154
+ _extends = Object.assign ? Object.assign.bind() : function (target) {
2155
+ for (var i = 1; i < arguments.length; i++) {
2156
+ var source = arguments[i];
2157
+ for (var key in source) {
2158
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
2159
+ target[key] = source[key];
2160
+ }
2161
+ }
2162
+ }
2163
+ return target;
2164
+ };
2165
+ return _extends.apply(this, arguments);
2195
2166
  }
2196
2167
 
2197
2168
  Route.__onInit = route => {
@@ -2765,8 +2736,48 @@
2765
2736
  return true;
2766
2737
  }
2767
2738
 
2739
+ const useLayoutEffect = typeof window !== 'undefined' ? React__namespace.useLayoutEffect : React__namespace.useEffect;
2740
+ function useScrollRestoration(options) {
2741
+ const router = useRouter();
2742
+ useLayoutEffect(() => {
2743
+ return watchScrollPositions(router, options);
2744
+ }, []);
2745
+ useLayoutEffect(() => {
2746
+ restoreScrollPositions(router, options);
2747
+ });
2748
+ }
2749
+ function ScrollRestoration(props) {
2750
+ useScrollRestoration(props);
2751
+ return null;
2752
+ }
2753
+
2754
+ function useAwaited({
2755
+ promise
2756
+ }) {
2757
+ const router = useRouter();
2758
+ let state = promise.__deferredState;
2759
+ const key = `__TSR__DEFERRED__${state.uid}`;
2760
+ if (isDehydratedDeferred(promise)) {
2761
+ state = router.hydrateData(key);
2762
+ promise = Promise.resolve(state.data);
2763
+ promise.__deferredState = state;
2764
+ }
2765
+ if (state.status === 'pending') {
2766
+ throw promise;
2767
+ }
2768
+ if (state.status === 'error') {
2769
+ throw state.error;
2770
+ }
2771
+ router.dehydrateData(key, state);
2772
+ return [state.data];
2773
+ }
2774
+ function Await(props) {
2775
+ const awaited = useAwaited(props);
2776
+ return props.children(...awaited);
2777
+ }
2778
+
2779
+ exports.Await = Await;
2768
2780
  exports.Block = Block;
2769
- exports.Deferred = Deferred;
2770
2781
  exports.ErrorComponent = ErrorComponent;
2771
2782
  exports.FileRoute = FileRoute;
2772
2783
  exports.Link = Link;
@@ -2819,8 +2830,8 @@
2819
2830
  exports.trimPath = trimPath;
2820
2831
  exports.trimPathLeft = trimPathLeft;
2821
2832
  exports.trimPathRight = trimPathRight;
2833
+ exports.useAwaited = useAwaited;
2822
2834
  exports.useBlocker = useBlocker;
2823
- exports.useDeferred = useDeferred;
2824
2835
  exports.useDehydrate = useDehydrate;
2825
2836
  exports.useHydrate = useHydrate;
2826
2837
  exports.useInjectHtml = useInjectHtml;