@tanstack/react-router 0.0.1-beta.1 → 0.0.1-beta.11

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.
@@ -991,6 +991,12 @@
991
991
 
992
992
  return updater;
993
993
  }
994
+ function pick(parent, keys) {
995
+ return keys.reduce((obj, key) => {
996
+ obj[key] = parent[key];
997
+ return obj;
998
+ }, {});
999
+ }
994
1000
 
995
1001
  function joinPaths(paths) {
996
1002
  return cleanPath(paths.filter(Boolean).join('/'));
@@ -1217,6 +1223,7 @@
1217
1223
  var str = decodeURIComponent(mix);
1218
1224
  if (str === 'false') return false;
1219
1225
  if (str === 'true') return true;
1226
+ if (str.charAt(0) === '0') return str;
1220
1227
  return +str * 0 === 0 ? +str : str;
1221
1228
  }
1222
1229
 
@@ -1267,7 +1274,7 @@
1267
1274
 
1268
1275
  const action = router.state.actions[id] || (() => {
1269
1276
  router.state.actions[id] = {
1270
- pending: [],
1277
+ submissions: [],
1271
1278
  submit: async (submission, actionOpts) => {
1272
1279
  var _actionOpts$invalidat;
1273
1280
 
@@ -1276,18 +1283,20 @@
1276
1283
  }
1277
1284
 
1278
1285
  const invalidate = (_actionOpts$invalidat = actionOpts == null ? void 0 : actionOpts.invalidate) != null ? _actionOpts$invalidat : true;
1286
+
1287
+ if (!(actionOpts != null && actionOpts.multi)) {
1288
+ action.submissions = action.submissions.filter(d => d.isMulti);
1289
+ }
1290
+
1279
1291
  const actionState = {
1280
1292
  submittedAt: Date.now(),
1281
1293
  status: 'pending',
1282
- submission
1294
+ submission,
1295
+ isMulti: !!(actionOpts != null && actionOpts.multi)
1283
1296
  };
1284
1297
  action.current = actionState;
1285
1298
  action.latest = actionState;
1286
- action.pending.push(actionState);
1287
- router.state = _extends({}, router.state, {
1288
- currentAction: actionState,
1289
- latestAction: actionState
1290
- });
1299
+ action.submissions.push(actionState);
1291
1300
  router.notify();
1292
1301
 
1293
1302
  try {
@@ -1309,11 +1318,6 @@
1309
1318
  actionState.error = err;
1310
1319
  actionState.status = 'error';
1311
1320
  } finally {
1312
- action.pending = action.pending.filter(d => d !== actionState);
1313
- router.removeActionQueue.push({
1314
- action,
1315
- actionState
1316
- });
1317
1321
  router.notify();
1318
1322
  }
1319
1323
  }
@@ -1388,15 +1392,6 @@
1388
1392
  });
1389
1393
  return route;
1390
1394
  }
1391
- function cascadeLoaderData(matches) {
1392
- matches.forEach((match, index) => {
1393
- const parent = matches[index - 1];
1394
-
1395
- if (parent) {
1396
- match.loaderData = replaceEqualDeep(match.loaderData, _extends({}, parent.loaderData, match.routeLoaderData));
1397
- }
1398
- });
1399
- }
1400
1395
 
1401
1396
  const rootRouteId = '__root__';
1402
1397
  const createRouteConfig = function createRouteConfig(options, children, isRoot, parentId, parentPath) {
@@ -1462,6 +1457,7 @@
1462
1457
  isFetching: false,
1463
1458
  isInvalid: false,
1464
1459
  invalidAt: Infinity,
1460
+ // pendingActions: [],
1465
1461
  getIsInvalid: () => {
1466
1462
  const now = Date.now();
1467
1463
  return routeMatch.isInvalid || routeMatch.invalidAt < now;
@@ -1501,17 +1497,6 @@
1501
1497
  clearTimeout(routeMatch.__.pendingMinTimeout);
1502
1498
  delete routeMatch.__.pendingMinPromise;
1503
1499
  },
1504
- // setParentMatch: (parentMatch?: RouteMatch) => {
1505
- // routeMatch.parentMatch = parentMatch
1506
- // },
1507
- // addChildMatch: (childMatch: RouteMatch) => {
1508
- // if (
1509
- // routeMatch.childMatches.find((d) => d.matchId === childMatch.matchId)
1510
- // ) {
1511
- // return
1512
- // }
1513
- // routeMatch.childMatches.push(childMatch)
1514
- // },
1515
1500
  validate: () => {
1516
1501
  var _routeMatch$parentMat, _routeMatch$parentMat2;
1517
1502
 
@@ -1519,9 +1504,11 @@
1519
1504
  const parentSearch = (_routeMatch$parentMat = (_routeMatch$parentMat2 = routeMatch.parentMatch) == null ? void 0 : _routeMatch$parentMat2.search) != null ? _routeMatch$parentMat : router.location.search;
1520
1505
 
1521
1506
  try {
1507
+ var _validator;
1508
+
1522
1509
  const prevSearch = routeMatch.routeSearch;
1523
1510
  const validator = typeof routeMatch.options.validateSearch === 'object' ? routeMatch.options.validateSearch.parse : routeMatch.options.validateSearch;
1524
- let nextSearch = replaceEqualDeep(prevSearch, validator == null ? void 0 : validator(parentSearch)); // Invalidate route matches when search param stability changes
1511
+ let nextSearch = replaceEqualDeep(prevSearch, (_validator = validator == null ? void 0 : validator(parentSearch)) != null ? _validator : {}); // Invalidate route matches when search param stability changes
1525
1512
 
1526
1513
  if (prevSearch !== nextSearch) {
1527
1514
  routeMatch.isInvalid = true;
@@ -1529,6 +1516,13 @@
1529
1516
 
1530
1517
  routeMatch.routeSearch = nextSearch;
1531
1518
  routeMatch.search = replaceEqualDeep(parentSearch, _extends({}, parentSearch, nextSearch));
1519
+ elementTypes.map(async type => {
1520
+ const routeElement = routeMatch.options[type];
1521
+
1522
+ if (typeof routeMatch.__[type] !== 'function') {
1523
+ routeMatch.__[type] = routeElement;
1524
+ }
1525
+ });
1532
1526
  } catch (err) {
1533
1527
  console.error(err);
1534
1528
  const error = new Error('Invalid search params found', {
@@ -1574,7 +1568,7 @@
1574
1568
 
1575
1569
  if (routeMatch.status === 'success' && routeMatch.getIsInvalid() || routeMatch.status === 'error' || routeMatch.status === 'idle') {
1576
1570
  const maxAge = loaderOpts != null && loaderOpts.preload ? loaderOpts == null ? void 0 : loaderOpts.maxAge : undefined;
1577
- routeMatch.fetch({
1571
+ await routeMatch.fetch({
1578
1572
  maxAge
1579
1573
  });
1580
1574
  }
@@ -1597,7 +1591,7 @@
1597
1591
  routeMatch.isFetching = true;
1598
1592
  routeMatch.__.resolve = resolve;
1599
1593
 
1600
- const loaderPromise = (async () => {
1594
+ routeMatch.__.loaderDataPromise = (async () => {
1601
1595
  // Load the elements and data in parallel
1602
1596
  routeMatch.__.elementsPromise = (async () => {
1603
1597
  // then run all element and data loaders in parallel
@@ -1605,11 +1599,9 @@
1605
1599
  await Promise.all(elementTypes.map(async type => {
1606
1600
  const routeElement = routeMatch.options[type];
1607
1601
 
1608
- if (routeMatch.__[type]) {
1609
- return;
1602
+ if (typeof routeMatch.__[type] === 'function') {
1603
+ routeMatch.__[type] = await router.options.createElement(routeElement);
1610
1604
  }
1611
-
1612
- routeMatch.__[type] = await router.options.createElement(routeElement);
1613
1605
  }));
1614
1606
  })();
1615
1607
 
@@ -1625,7 +1617,7 @@
1625
1617
  });
1626
1618
 
1627
1619
  if (id !== routeMatch.__.latestId) {
1628
- return routeMatch.__.loaderPromise;
1620
+ return routeMatch.__.loadPromise;
1629
1621
  }
1630
1622
 
1631
1623
  routeMatch.routeLoaderData = replaceEqualDeep(routeMatch.routeLoaderData, data);
@@ -1637,7 +1629,7 @@
1637
1629
  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);
1638
1630
  } catch (err) {
1639
1631
  if (id !== routeMatch.__.latestId) {
1640
- return routeMatch.__.loaderPromise;
1632
+ return routeMatch.__.loadPromise;
1641
1633
  }
1642
1634
 
1643
1635
  {
@@ -1654,7 +1646,7 @@
1654
1646
  await Promise.all([routeMatch.__.elementsPromise, routeMatch.__.dataPromise]);
1655
1647
 
1656
1648
  if (id !== routeMatch.__.latestId) {
1657
- return routeMatch.__.loaderPromise;
1649
+ return routeMatch.__.loadPromise;
1658
1650
  }
1659
1651
 
1660
1652
  if (routeMatch.__.pendingMinPromise) {
@@ -1663,7 +1655,7 @@
1663
1655
  }
1664
1656
  } finally {
1665
1657
  if (id !== routeMatch.__.latestId) {
1666
- return routeMatch.__.loaderPromise;
1658
+ return routeMatch.__.loadPromise;
1667
1659
  }
1668
1660
 
1669
1661
  routeMatch.__.cancelPending();
@@ -1675,16 +1667,16 @@
1675
1667
  }
1676
1668
  })();
1677
1669
 
1678
- routeMatch.__.loaderPromise = loaderPromise;
1679
- await loaderPromise;
1670
+ await routeMatch.__.loaderDataPromise;
1680
1671
 
1681
1672
  if (id !== routeMatch.__.latestId) {
1682
- return routeMatch.__.loaderPromise;
1673
+ return routeMatch.__.loadPromise;
1683
1674
  }
1684
1675
 
1685
- delete routeMatch.__.loaderPromise;
1676
+ delete routeMatch.__.loaderDataPromise;
1686
1677
  });
1687
- return await routeMatch.__.loadPromise;
1678
+ await routeMatch.__.loadPromise;
1679
+ delete routeMatch.__.loadPromise;
1688
1680
  }
1689
1681
  });
1690
1682
 
@@ -1745,9 +1737,22 @@
1745
1737
 
1746
1738
  var _window$document;
1747
1739
  // Detect if we're in the DOM
1748
- const isServer = Boolean(typeof window === 'undefined' || !((_window$document = window.document) != null && _window$document.createElement)); // This is the default history object if none is defined
1740
+ const isServer = typeof window === 'undefined' || !((_window$document = window.document) != null && _window$document.createElement); // This is the default history object if none is defined
1749
1741
 
1750
- const createDefaultHistory = () => !isServer ? createBrowserHistory() : createMemoryHistory();
1742
+ const createDefaultHistory = () => isServer ? createMemoryHistory() : createBrowserHistory();
1743
+
1744
+ function getInitialRouterState() {
1745
+ return {
1746
+ status: 'idle',
1747
+ location: null,
1748
+ matches: [],
1749
+ actions: {},
1750
+ loaders: {},
1751
+ lastUpdated: Date.now(),
1752
+ isFetching: false,
1753
+ isPreloading: false
1754
+ };
1755
+ }
1751
1756
 
1752
1757
  function createRouter(userOptions) {
1753
1758
  var _userOptions$stringif, _userOptions$parseSea;
@@ -1768,7 +1773,6 @@
1768
1773
  history,
1769
1774
  options: originalOptions,
1770
1775
  listeners: [],
1771
- removeActionQueue: [],
1772
1776
  // Resolved after construction
1773
1777
  basepath: '',
1774
1778
  routeTree: undefined,
@@ -1779,16 +1783,10 @@
1779
1783
  navigationPromise: Promise.resolve(),
1780
1784
  resolveNavigation: () => {},
1781
1785
  matchCache: {},
1782
- state: {
1783
- status: 'idle',
1784
- location: null,
1785
- matches: [],
1786
- actions: {},
1787
- loaders: {},
1788
- loaderData: {},
1789
- lastUpdated: Date.now(),
1790
- isFetching: false,
1791
- isPreloading: false
1786
+ state: getInitialRouterState(),
1787
+ reset: () => {
1788
+ router.state = getInitialRouterState();
1789
+ router.notify();
1792
1790
  },
1793
1791
  startedLoadingAt: Date.now(),
1794
1792
  subscribe: listener => {
@@ -1806,7 +1804,27 @@
1806
1804
  isPreloading: Object.values(router.matchCache).some(d => d.match.isFetching && !router.state.matches.find(dd => dd.matchId === d.match.matchId))
1807
1805
  });
1808
1806
  cascadeLoaderData(router.state.matches);
1809
- router.listeners.forEach(listener => listener());
1807
+ router.listeners.forEach(listener => listener(router));
1808
+ },
1809
+ dehydrateState: () => {
1810
+ return _extends({}, pick(router.state, ['status', 'location', 'lastUpdated']), {
1811
+ matches: router.state.matches.map(match => pick(match, ['matchId', 'status', 'routeLoaderData', 'loaderData', 'isInvalid', 'invalidAt']))
1812
+ });
1813
+ },
1814
+ hydrateState: dehydratedState => {
1815
+ // Match the routes
1816
+ const matches = router.matchRoutes(router.location.pathname, {
1817
+ strictParseParams: true
1818
+ });
1819
+ matches.forEach((match, index) => {
1820
+ const dehydratedMatch = dehydratedState.matches[index];
1821
+ invariant(dehydratedMatch, 'Oh no! Dehydrated route matches did not match the active state of the router 😬');
1822
+ Object.assign(match, dehydratedMatch);
1823
+ });
1824
+ router.loadMatches(matches);
1825
+ router.state = _extends({}, router.state, dehydratedState, {
1826
+ matches
1827
+ });
1810
1828
  },
1811
1829
  mount: () => {
1812
1830
  const next = router.__.buildLocation({
@@ -1819,12 +1837,11 @@
1819
1837
 
1820
1838
  if (next.href !== router.location.href) {
1821
1839
  router.__.commitLocation(next, true);
1822
- } else {
1823
- router.loadLocation();
1824
- }
1840
+ } // router.load()
1841
+
1825
1842
 
1826
- const unsub = history.listen(event => {
1827
- router.loadLocation(router.__.parseLocation(event.location, router.location));
1843
+ const unsub = router.history.listen(event => {
1844
+ router.load(router.__.parseLocation(event.location, router.location));
1828
1845
  }); // addEventListener does not exist in React Native, but window does
1829
1846
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
1830
1847
 
@@ -1835,16 +1852,30 @@
1835
1852
  }
1836
1853
 
1837
1854
  return () => {
1838
- unsub(); // Be sure to unsubscribe if a new handler is set
1855
+ unsub();
1839
1856
 
1840
- window.removeEventListener('visibilitychange', router.onFocus);
1841
- window.removeEventListener('focus', router.onFocus);
1857
+ if (!isServer && window.removeEventListener) {
1858
+ // Be sure to unsubscribe if a new handler is set
1859
+ window.removeEventListener('visibilitychange', router.onFocus);
1860
+ window.removeEventListener('focus', router.onFocus);
1861
+ }
1842
1862
  };
1843
1863
  },
1844
1864
  onFocus: () => {
1845
- router.loadLocation();
1865
+ router.load();
1846
1866
  },
1847
1867
  update: opts => {
1868
+ const newHistory = (opts == null ? void 0 : opts.history) !== router.history;
1869
+
1870
+ if (!router.location || newHistory) {
1871
+ if (opts != null && opts.history) {
1872
+ router.history = opts.history;
1873
+ }
1874
+
1875
+ router.location = router.__.parseLocation(router.history.location);
1876
+ router.state.location = router.location;
1877
+ }
1878
+
1848
1879
  Object.assign(router.options, opts);
1849
1880
  const {
1850
1881
  basepath,
@@ -1865,35 +1896,19 @@
1865
1896
  match.cancel();
1866
1897
  });
1867
1898
  },
1868
- loadLocation: async next => {
1899
+ load: async next => {
1869
1900
  const id = Math.random();
1870
1901
  router.startedLoadingAt = id;
1871
1902
 
1872
1903
  if (next) {
1873
1904
  // Ingest the new location
1874
1905
  router.location = next;
1875
- } // Clear out old actions
1876
-
1877
-
1878
- router.removeActionQueue.forEach(_ref => {
1879
- let {
1880
- action,
1881
- actionState
1882
- } = _ref;
1883
-
1884
- if (router.state.currentAction === actionState) {
1885
- router.state.currentAction = undefined;
1886
- }
1906
+ } // Cancel any pending matches
1887
1907
 
1888
- if (action.current === actionState) {
1889
- action.current = undefined;
1890
- }
1891
- });
1892
- router.removeActionQueue = []; // Cancel any pending matches
1893
1908
 
1894
1909
  router.cancelMatches(); // Match the routes
1895
1910
 
1896
- const matches = router.matchRoutes(location.pathname, {
1911
+ const matches = router.matchRoutes(router.location.pathname, {
1897
1912
  strictParseParams: true
1898
1913
  });
1899
1914
  router.state = _extends({}, router.state, {
@@ -1924,9 +1939,12 @@
1924
1939
  exiting.push(d);
1925
1940
  }
1926
1941
  });
1942
+ const entering = matches.filter(d => {
1943
+ return !previousMatches.find(dd => dd.matchId === d.matchId);
1944
+ });
1927
1945
  const now = Date.now();
1928
1946
  exiting.forEach(d => {
1929
- var _ref2, _d$options$loaderGcMa, _ref3, _d$options$loaderMaxA;
1947
+ var _ref, _d$options$loaderGcMa, _ref2, _d$options$loaderMaxA;
1930
1948
 
1931
1949
  d.__.onExit == null ? void 0 : d.__.onExit({
1932
1950
  params: d.params,
@@ -1938,7 +1956,7 @@
1938
1956
  d.error = undefined;
1939
1957
  }
1940
1958
 
1941
- const gc = Math.max((_ref2 = (_d$options$loaderGcMa = d.options.loaderGcMaxAge) != null ? _d$options$loaderGcMa : router.options.defaultLoaderGcMaxAge) != null ? _ref2 : 0, (_ref3 = (_d$options$loaderMaxA = d.options.loaderMaxAge) != null ? _d$options$loaderMaxA : router.options.defaultLoaderMaxAge) != null ? _ref3 : 0);
1959
+ const gc = Math.max((_ref = (_d$options$loaderGcMa = d.options.loaderGcMaxAge) != null ? _d$options$loaderGcMa : router.options.defaultLoaderGcMaxAge) != null ? _ref : 0, (_ref2 = (_d$options$loaderMaxA = d.options.loaderMaxAge) != null ? _d$options$loaderMaxA : router.options.defaultLoaderMaxAge) != null ? _ref2 : 0);
1942
1960
 
1943
1961
  if (gc > 0) {
1944
1962
  router.matchCache[d.matchId] = {
@@ -1953,9 +1971,6 @@
1953
1971
  search: d.routeSearch
1954
1972
  });
1955
1973
  });
1956
- const entering = matches.filter(d => {
1957
- return !previousMatches.find(dd => dd.matchId === d.matchId);
1958
- });
1959
1974
  entering.forEach(d => {
1960
1975
  d.__.onExit = d.options.onMatch == null ? void 0 : d.options.onMatch({
1961
1976
  params: d.params,
@@ -1964,16 +1979,18 @@
1964
1979
  delete router.matchCache[d.matchId];
1965
1980
  });
1966
1981
 
1967
- if (matches.some(d => d.status === 'loading')) {
1968
- router.notify();
1969
- await Promise.all(matches.map(d => d.__.loaderPromise || Promise.resolve()));
1970
- }
1971
-
1972
1982
  if (router.startedLoadingAt !== id) {
1973
1983
  // Ignore side-effects of match loading
1974
1984
  return;
1975
1985
  }
1976
1986
 
1987
+ matches.forEach(match => {
1988
+ // Clear actions
1989
+ if (match.action) {
1990
+ match.action.current = undefined;
1991
+ match.action.submissions = [];
1992
+ }
1993
+ });
1977
1994
  router.state = _extends({}, router.state, {
1978
1995
  location: router.location,
1979
1996
  matches,
@@ -2014,7 +2031,7 @@
2014
2031
  return matches;
2015
2032
  },
2016
2033
  preloadRoute: async function preloadRoute(navigateOpts, loaderOpts) {
2017
- var _ref4, _ref5, _loaderOpts$maxAge, _ref6, _ref7, _loaderOpts$gcMaxAge;
2034
+ var _ref3, _ref4, _loaderOpts$maxAge, _ref5, _ref6, _loaderOpts$gcMaxAge;
2018
2035
 
2019
2036
  if (navigateOpts === void 0) {
2020
2037
  navigateOpts = router.location;
@@ -2026,8 +2043,8 @@
2026
2043
  });
2027
2044
  await router.loadMatches(matches, {
2028
2045
  preload: true,
2029
- maxAge: (_ref4 = (_ref5 = (_loaderOpts$maxAge = loaderOpts.maxAge) != null ? _loaderOpts$maxAge : router.options.defaultPreloadMaxAge) != null ? _ref5 : router.options.defaultLoaderMaxAge) != null ? _ref4 : 0,
2030
- gcMaxAge: (_ref6 = (_ref7 = (_loaderOpts$gcMaxAge = loaderOpts.gcMaxAge) != null ? _loaderOpts$gcMaxAge : router.options.defaultPreloadGcMaxAge) != null ? _ref7 : router.options.defaultLoaderGcMaxAge) != null ? _ref6 : 0
2046
+ maxAge: (_ref3 = (_ref4 = (_loaderOpts$maxAge = loaderOpts.maxAge) != null ? _loaderOpts$maxAge : router.options.defaultPreloadMaxAge) != null ? _ref4 : router.options.defaultLoaderMaxAge) != null ? _ref3 : 0,
2047
+ gcMaxAge: (_ref5 = (_ref6 = (_loaderOpts$gcMaxAge = loaderOpts.gcMaxAge) != null ? _loaderOpts$gcMaxAge : router.options.defaultPreloadGcMaxAge) != null ? _ref6 : router.options.defaultLoaderGcMaxAge) != null ? _ref5 : 0
2031
2048
  });
2032
2049
  return matches;
2033
2050
  },
@@ -2129,9 +2146,12 @@
2129
2146
 
2130
2147
  if (match.status === 'loading') {
2131
2148
  // If requested, start the pending timers
2132
- if (loaderOpts != null && loaderOpts.withPending) match.__.startPending(); // Wait for the first sign of activity from the match
2133
- // This might be completion, error, or a pending state
2149
+ if (loaderOpts != null && loaderOpts.withPending) match.__.startPending();
2150
+ }
2134
2151
 
2152
+ if (match.__.loadPromise) {
2153
+ // Wait for the first sign of activity from the match
2154
+ // This might be completion, error, or a pending state
2135
2155
  await match.__.loadPromise;
2136
2156
  }
2137
2157
  });
@@ -2182,7 +2202,7 @@
2182
2202
  to: next.pathname
2183
2203
  }));
2184
2204
  },
2185
- navigate: async _ref8 => {
2205
+ navigate: async _ref7 => {
2186
2206
  let {
2187
2207
  from,
2188
2208
  to = '.',
@@ -2190,7 +2210,7 @@
2190
2210
  hash,
2191
2211
  replace,
2192
2212
  params
2193
- } = _ref8;
2213
+ } = _ref7;
2194
2214
  // If this link simply reloads the current route,
2195
2215
  // make sure it has a new key so it will trigger a data refresh
2196
2216
  // If this `to` is a valid external URL, return
@@ -2214,8 +2234,8 @@
2214
2234
  params
2215
2235
  });
2216
2236
  },
2217
- buildLink: _ref9 => {
2218
- var _preload, _ref10;
2237
+ buildLink: _ref8 => {
2238
+ var _preload, _ref9;
2219
2239
 
2220
2240
  let {
2221
2241
  from,
@@ -2231,7 +2251,7 @@
2231
2251
  preloadGcMaxAge: userPreloadGcMaxAge,
2232
2252
  preloadDelay: userPreloadDelay,
2233
2253
  disabled
2234
- } = _ref9;
2254
+ } = _ref8;
2235
2255
 
2236
2256
  // If this link simply reloads the current route,
2237
2257
  // make sure it has a new key so it will trigger a data refresh
@@ -2255,7 +2275,7 @@
2255
2275
  };
2256
2276
  const next = router.buildNext(nextOpts);
2257
2277
  preload = (_preload = preload) != null ? _preload : router.options.defaultPreload;
2258
- const preloadDelay = (_ref10 = userPreloadDelay != null ? userPreloadDelay : router.options.defaultPreloadDelay) != null ? _ref10 : 0; // Compare path/hash for matches
2278
+ const preloadDelay = (_ref9 = userPreloadDelay != null ? userPreloadDelay : router.options.defaultPreloadDelay) != null ? _ref9 : 0; // Compare path/hash for matches
2259
2279
 
2260
2280
  const pathIsEqual = router.state.location.pathname === next.pathname;
2261
2281
  const currentPathSplit = router.state.location.pathname.split('/');
@@ -2356,11 +2376,7 @@
2356
2376
  const recurseRoutes = (routeConfigs, parent) => {
2357
2377
  return routeConfigs.map(routeConfig => {
2358
2378
  const routeOptions = routeConfig.options;
2359
- const route = createRoute(routeConfig, routeOptions, parent, router); // {
2360
- // pendingMs: routeOptions.pendingMs ?? router.defaultPendingMs,
2361
- // pendingMinMs: routeOptions.pendingMinMs ?? router.defaultPendingMinMs,
2362
- // }
2363
-
2379
+ const route = createRoute(routeConfig, routeOptions, parent, router);
2364
2380
  const existingRoute = router.routesById[route.routeId];
2365
2381
 
2366
2382
  if (existingRoute) {
@@ -2495,8 +2511,6 @@
2495
2511
  }
2496
2512
  }
2497
2513
  };
2498
- router.location = router.__.parseLocation(history.location);
2499
- router.state.location = router.location;
2500
2514
  router.update(userOptions); // Allow frameworks to hook into the router creation
2501
2515
 
2502
2516
  router.options.createRouter == null ? void 0 : router.options.createRouter(router);
@@ -2507,6 +2521,16 @@
2507
2521
  return !!(e.metaKey || e.altKey || e.ctrlKey || e.shiftKey);
2508
2522
  }
2509
2523
 
2524
+ function cascadeLoaderData(matches) {
2525
+ matches.forEach((match, index) => {
2526
+ const parent = matches[index - 1];
2527
+
2528
+ if (parent) {
2529
+ match.loaderData = replaceEqualDeep(match.loaderData, _extends({}, parent.loaderData, match.routeLoaderData));
2530
+ }
2531
+ });
2532
+ }
2533
+
2510
2534
  const _excluded = ["type", "children", "target", "activeProps", "inactiveProps", "activeOptions", "disabled", "hash", "search", "params", "to", "preload", "preloadDelay", "preloadMaxAge", "replace", "style", "className", "onClick", "onFocus", "onMouseEnter", "onMouseLeave", "onTouchStart", "onTouchEnd"],
2511
2535
  _excluded2 = ["pending", "caseSensitive", "children"],
2512
2536
  _excluded3 = ["children", "router"];
@@ -2521,7 +2545,7 @@
2521
2545
  }
2522
2546
 
2523
2547
  const useRouterSubscription = router => {
2524
- shim.useSyncExternalStore(cb => router.subscribe(() => cb()), () => router.state);
2548
+ shim.useSyncExternalStore(cb => router.subscribe(() => cb()), () => router.state, () => router.state);
2525
2549
  };
2526
2550
 
2527
2551
  function createReactRouter(opts) {
@@ -2645,18 +2669,17 @@
2645
2669
  useRouterSubscription(router);
2646
2670
  return router.state;
2647
2671
  },
2648
- useMatch: routeId => {
2672
+ useMatch: (routeId, opts) => {
2673
+ var _useMatches, _opts$strict;
2674
+
2649
2675
  useRouterSubscription(router);
2650
2676
  invariant(routeId !== rootRouteId, "\"" + rootRouteId + "\" cannot be used with useMatch! Did you mean to useRoute(\"" + rootRouteId + "\")?");
2651
-
2652
- const runtimeMatch = _useMatch();
2653
-
2677
+ const runtimeMatch = (_useMatches = useMatches()) == null ? void 0 : _useMatches[0];
2654
2678
  const match = router.state.matches.find(d => d.routeId === routeId);
2655
- invariant(match, "Could not find a match for route \"" + routeId + "\" being rendered in this component!");
2656
- invariant(runtimeMatch.routeId == (match == null ? void 0 : match.routeId), "useMatch('" + (match == null ? void 0 : match.routeId) + "') is being called in a component that is meant to render the '" + runtimeMatch.routeId + "' route. Did you mean to 'useRoute(" + (match == null ? void 0 : match.routeId) + ")' instead?");
2657
2679
 
2658
- if (!match) {
2659
- invariant('Match not found!');
2680
+ if ((_opts$strict = opts == null ? void 0 : opts.strict) != null ? _opts$strict : true) {
2681
+ invariant(match, "Could not find an active match for \"" + routeId + "\"!");
2682
+ invariant(runtimeMatch.routeId == (match == null ? void 0 : match.routeId), "useMatch('" + (match == null ? void 0 : match.routeId) + "') is being called in a component that is meant to render the '" + runtimeMatch.routeId + "' route. Did you mean to 'useMatch(" + (match == null ? void 0 : match.routeId) + ", { strict: false })' or 'useRoute(" + (match == null ? void 0 : match.routeId) + ")' instead?");
2660
2683
  }
2661
2684
 
2662
2685
  return match;
@@ -2699,7 +2722,9 @@
2699
2722
  router.update(rest);
2700
2723
  useRouterSubscription(router);
2701
2724
  useLayoutEffect(() => {
2702
- return router.mount();
2725
+ const unsub = router.mount();
2726
+ router.load();
2727
+ return unsub;
2703
2728
  }, [router]);
2704
2729
  return /*#__PURE__*/React__namespace.createElement(routerContext.Provider, {
2705
2730
  value: {
@@ -2719,61 +2744,49 @@
2719
2744
 
2720
2745
  function useMatches() {
2721
2746
  return React__namespace.useContext(matchesContext);
2722
- } // function useParentMatches(): RouteMatch[] {
2723
- // const router = useRouter()
2724
- // const match = useMatch()
2725
- // const matches = router.state.matches
2726
- // return matches.slice(
2727
- // 0,
2728
- // matches.findIndex((d) => d.matchId === match.matchId) - 1,
2729
- // )
2730
- // }
2731
-
2732
-
2733
- function _useMatch() {
2734
- var _useMatches;
2735
-
2736
- return (_useMatches = useMatches()) == null ? void 0 : _useMatches[0];
2737
2747
  }
2738
2748
 
2739
2749
  function Outlet() {
2740
- var _childMatch$options$c;
2750
+ var _match$options$catchE;
2741
2751
 
2742
2752
  const router = useRouter();
2743
- const [, ...matches] = useMatches();
2744
- const childMatch = matches[0];
2745
- if (!childMatch) return null;
2753
+ const matches = useMatches().slice(1);
2754
+ const match = matches[0];
2755
+
2756
+ if (!match) {
2757
+ return null;
2758
+ }
2746
2759
 
2747
2760
  const element = (() => {
2748
- var _childMatch$__$errorE, _ref4;
2761
+ var _match$__$errorElemen, _ref4, _ref5;
2749
2762
 
2750
- if (!childMatch) {
2763
+ if (!match) {
2751
2764
  return null;
2752
2765
  }
2753
2766
 
2754
- const errorElement = (_childMatch$__$errorE = childMatch.__.errorElement) != null ? _childMatch$__$errorE : router.options.defaultErrorElement;
2767
+ const errorElement = (_match$__$errorElemen = match.__.errorElement) != null ? _match$__$errorElemen : router.options.defaultErrorElement;
2755
2768
 
2756
- if (childMatch.status === 'error') {
2769
+ if (match.status === 'error') {
2757
2770
  if (errorElement) {
2758
2771
  return errorElement;
2759
2772
  }
2760
2773
 
2761
- if (childMatch.options.useErrorBoundary || router.options.useErrorBoundary) {
2762
- throw childMatch.error;
2774
+ if (match.options.useErrorBoundary || router.options.useErrorBoundary) {
2775
+ throw match.error;
2763
2776
  }
2764
2777
 
2765
2778
  return /*#__PURE__*/React__namespace.createElement(DefaultErrorBoundary, {
2766
- error: childMatch.error
2779
+ error: match.error
2767
2780
  });
2768
2781
  }
2769
2782
 
2770
- if (childMatch.status === 'loading' || childMatch.status === 'idle') {
2771
- if (childMatch.isPending) {
2772
- var _childMatch$__$pendin;
2783
+ if (match.status === 'loading' || match.status === 'idle') {
2784
+ if (match.isPending) {
2785
+ var _match$__$pendingElem;
2773
2786
 
2774
- const pendingElement = (_childMatch$__$pendin = childMatch.__.pendingElement) != null ? _childMatch$__$pendin : router.options.defaultPendingElement;
2787
+ const pendingElement = (_match$__$pendingElem = match.__.pendingElement) != null ? _match$__$pendingElem : router.options.defaultPendingElement;
2775
2788
 
2776
- if (childMatch.options.pendingMs || pendingElement) {
2789
+ if (match.options.pendingMs || pendingElement) {
2777
2790
  var _ref3;
2778
2791
 
2779
2792
  return (_ref3 = pendingElement) != null ? _ref3 : null;
@@ -2783,13 +2796,12 @@
2783
2796
  return null;
2784
2797
  }
2785
2798
 
2786
- return (_ref4 = childMatch.__.element) != null ? _ref4 : router.options.defaultElement;
2799
+ return (_ref4 = (_ref5 = match.__.element) != null ? _ref5 : router.options.defaultElement) != null ? _ref4 : /*#__PURE__*/React__namespace.createElement(Outlet, null);
2787
2800
  })();
2788
2801
 
2789
- const catchElement = (_childMatch$options$c = childMatch == null ? void 0 : childMatch.options.catchElement) != null ? _childMatch$options$c : router.options.defaultCatchElement;
2802
+ const catchElement = (_match$options$catchE = match == null ? void 0 : match.options.catchElement) != null ? _match$options$catchE : router.options.defaultCatchElement;
2790
2803
  return /*#__PURE__*/React__namespace.createElement(MatchesProvider, {
2791
- value: matches,
2792
- key: childMatch.matchId
2804
+ value: matches
2793
2805
  }, /*#__PURE__*/React__namespace.createElement(CatchBoundary, {
2794
2806
  catchElement: catchElement
2795
2807
  }, element));
@@ -2801,13 +2813,6 @@
2801
2813
  this.state = {
2802
2814
  error: false
2803
2815
  };
2804
-
2805
- this.reset = () => {
2806
- this.setState({
2807
- error: false,
2808
- info: false
2809
- });
2810
- };
2811
2816
  }
2812
2817
 
2813
2818
  componentDidCatch(error, info) {
@@ -2832,10 +2837,10 @@
2832
2837
 
2833
2838
  }
2834
2839
 
2835
- function DefaultErrorBoundary(_ref5) {
2840
+ function DefaultErrorBoundary(_ref6) {
2836
2841
  let {
2837
2842
  error
2838
- } = _ref5;
2843
+ } = _ref6;
2839
2844
  return /*#__PURE__*/React__namespace.createElement("div", {
2840
2845
  style: {
2841
2846
  padding: '.5rem',
@@ -2857,18 +2862,7 @@
2857
2862
  padding: '.5rem',
2858
2863
  color: 'red'
2859
2864
  }
2860
- }, error.message) : null)), /*#__PURE__*/React__namespace.createElement("div", {
2861
- style: {
2862
- height: '1rem'
2863
- }
2864
- }), /*#__PURE__*/React__namespace.createElement("div", {
2865
- style: {
2866
- fontSize: '.8em',
2867
- borderLeft: '3px solid rgba(127, 127, 127, 1)',
2868
- paddingLeft: '.5rem',
2869
- opacity: 0.5
2870
- }
2871
- }, "If you are the owner of this website, it's highly recommended that you configure your own custom Catch/Error boundaries for the router. You can optionally configure a boundary for each route."));
2865
+ }, error.message) : null)));
2872
2866
  }
2873
2867
  function usePrompt(message, when) {
2874
2868
  const router = useRouter();
@@ -2885,12 +2879,12 @@
2885
2879
  return unblock;
2886
2880
  }, [when, location, message]);
2887
2881
  }
2888
- function Prompt(_ref6) {
2882
+ function Prompt(_ref7) {
2889
2883
  let {
2890
2884
  message,
2891
2885
  when,
2892
2886
  children
2893
- } = _ref6;
2887
+ } = _ref7;
2894
2888
  usePrompt(message, when != null ? when : true);
2895
2889
  return children != null ? children : null;
2896
2890
  }
@@ -2900,7 +2894,6 @@
2900
2894
  exports.Outlet = Outlet;
2901
2895
  exports.Prompt = Prompt;
2902
2896
  exports.RouterProvider = RouterProvider;
2903
- exports.cascadeLoaderData = cascadeLoaderData;
2904
2897
  exports.cleanPath = cleanPath;
2905
2898
  exports.createBrowserHistory = createBrowserHistory;
2906
2899
  exports.createHashHistory = createHashHistory;
@@ -2923,6 +2916,7 @@
2923
2916
  exports.matchPathname = matchPathname;
2924
2917
  exports.parsePathname = parsePathname;
2925
2918
  exports.parseSearchWith = parseSearchWith;
2919
+ exports.pick = pick;
2926
2920
  exports.replaceEqualDeep = replaceEqualDeep;
2927
2921
  exports.resolvePath = resolvePath;
2928
2922
  exports.rootRouteId = rootRouteId;