@tanstack/react-router 0.0.1-beta.4 → 0.0.1-beta.6

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.
@@ -975,6 +975,11 @@ function functionalUpdate(updater, previous) {
975
975
 
976
976
  return updater;
977
977
  }
978
+ function pick(parent, keys) {
979
+ return keys.reduce((obj, key) => {
980
+ obj[key] = parent[key];
981
+ }, {});
982
+ }
978
983
 
979
984
  function joinPaths(paths) {
980
985
  return cleanPath(paths.filter(Boolean).join('/'));
@@ -1770,7 +1775,6 @@ function createRouter(userOptions) {
1770
1775
  matches: [],
1771
1776
  actions: {},
1772
1777
  loaders: {},
1773
- loaderData: {},
1774
1778
  lastUpdated: Date.now(),
1775
1779
  isFetching: false,
1776
1780
  isPreloading: false
@@ -1793,6 +1797,26 @@ function createRouter(userOptions) {
1793
1797
  cascadeLoaderData(router.state.matches);
1794
1798
  router.listeners.forEach(listener => listener(router));
1795
1799
  },
1800
+ dehydrateState: () => {
1801
+ router.state;
1802
+ return _extends({}, pick(router.state, ['status', 'location', 'lastUpdated']), {
1803
+ matches: router.state.matches.map(match => pick(match, ['matchId', 'status', 'routeLoaderData', 'loaderData', 'isInvalid', 'invalidAt']))
1804
+ });
1805
+ },
1806
+ hydrateState: dehydratedState => {
1807
+ // Match the routes
1808
+ const matches = router.matchRoutes(router.location.pathname, {
1809
+ strictParseParams: true
1810
+ });
1811
+ router.state = _extends({}, router.state, dehydratedState, {
1812
+ matches: matches.map(match => {
1813
+ const dehydratedMatch = dehydratedState.matches.find(d => d.matchId === match.matchId);
1814
+ invariant(dehydratedMatch, 'Oh no! Dehydrated route matches did not match the active state of the router 😬');
1815
+ Object.assign(match, dehydratedMatch);
1816
+ return match;
1817
+ })
1818
+ });
1819
+ },
1796
1820
  mount: () => {
1797
1821
  const next = router.__.buildLocation({
1798
1822
  to: '.',
@@ -1804,11 +1828,11 @@ function createRouter(userOptions) {
1804
1828
 
1805
1829
  if (next.href !== router.location.href) {
1806
1830
  router.__.commitLocation(next, true);
1807
- } else {
1808
- router.loadLocation();
1809
1831
  }
1810
1832
 
1811
- const unsub = history.listen(event => {
1833
+ router.loadLocation();
1834
+ const unsub = router.history.listen(event => {
1835
+ console.log(event.location);
1812
1836
  router.loadLocation(router.__.parseLocation(event.location, router.location));
1813
1837
  }); // addEventListener does not exist in React Native, but window does
1814
1838
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
@@ -1830,6 +1854,17 @@ function createRouter(userOptions) {
1830
1854
  router.loadLocation();
1831
1855
  },
1832
1856
  update: opts => {
1857
+ const newHistory = (opts == null ? void 0 : opts.history) !== router.history;
1858
+
1859
+ if (!router.location || newHistory) {
1860
+ if (opts != null && opts.history) {
1861
+ router.history = opts.history;
1862
+ }
1863
+
1864
+ router.location = router.__.parseLocation(router.history.location);
1865
+ router.state.location = router.location;
1866
+ }
1867
+
1833
1868
  Object.assign(router.options, opts);
1834
1869
  const {
1835
1870
  basepath,
@@ -1878,7 +1913,7 @@ function createRouter(userOptions) {
1878
1913
 
1879
1914
  router.cancelMatches(); // Match the routes
1880
1915
 
1881
- const matches = router.matchRoutes(location.pathname, {
1916
+ const matches = router.matchRoutes(router.location.pathname, {
1882
1917
  strictParseParams: true
1883
1918
  });
1884
1919
  router.state = _extends({}, router.state, {
@@ -2341,11 +2376,7 @@ function createRouter(userOptions) {
2341
2376
  const recurseRoutes = (routeConfigs, parent) => {
2342
2377
  return routeConfigs.map(routeConfig => {
2343
2378
  const routeOptions = routeConfig.options;
2344
- const route = createRoute(routeConfig, routeOptions, parent, router); // {
2345
- // pendingMs: routeOptions.pendingMs ?? router.defaultPendingMs,
2346
- // pendingMinMs: routeOptions.pendingMinMs ?? router.defaultPendingMinMs,
2347
- // }
2348
-
2379
+ const route = createRoute(routeConfig, routeOptions, parent, router);
2349
2380
  const existingRoute = router.routesById[route.routeId];
2350
2381
 
2351
2382
  if (existingRoute) {
@@ -2480,8 +2511,6 @@ function createRouter(userOptions) {
2480
2511
  }
2481
2512
  }
2482
2513
  };
2483
- router.location = router.__.parseLocation(history.location);
2484
- router.state.location = router.location;
2485
2514
  router.update(userOptions); // Allow frameworks to hook into the router creation
2486
2515
 
2487
2516
  router.options.createRouter == null ? void 0 : router.options.createRouter(router);
@@ -2786,13 +2815,6 @@ class CatchBoundary extends React.Component {
2786
2815
  this.state = {
2787
2816
  error: false
2788
2817
  };
2789
-
2790
- this.reset = () => {
2791
- this.setState({
2792
- error: false,
2793
- info: false
2794
- });
2795
- };
2796
2818
  }
2797
2819
 
2798
2820
  componentDidCatch(error, info) {
@@ -2880,5 +2902,5 @@ function Prompt(_ref6) {
2880
2902
  return children != null ? children : null;
2881
2903
  }
2882
2904
 
2883
- export { DefaultErrorBoundary, MatchesProvider, Outlet, Prompt, RouterProvider, cascadeLoaderData, cleanPath, createBrowserHistory, createHashHistory, createMemoryHistory, createReactRouter, createRoute, createRouteConfig, createRouteMatch, createRouter, decode, defaultParseSearch, defaultStringifySearch, encode, functionalUpdate, interpolatePath, invariant, joinPaths, last, matchByPath, matchPathname, parsePathname, parseSearchWith, replaceEqualDeep, resolvePath, rootRouteId, stringifySearchWith, trimPath, trimPathLeft, trimPathRight, usePrompt, warning };
2905
+ export { DefaultErrorBoundary, MatchesProvider, Outlet, Prompt, RouterProvider, cascadeLoaderData, cleanPath, createBrowserHistory, createHashHistory, createMemoryHistory, createReactRouter, createRoute, createRouteConfig, createRouteMatch, createRouter, decode, defaultParseSearch, defaultStringifySearch, encode, functionalUpdate, interpolatePath, invariant, joinPaths, last, matchByPath, matchPathname, parsePathname, parseSearchWith, pick, replaceEqualDeep, resolvePath, rootRouteId, stringifySearchWith, trimPath, trimPathLeft, trimPathRight, usePrompt, warning };
2884
2906
  //# sourceMappingURL=index.js.map