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

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.
@@ -551,6 +551,15 @@ const rootRouteId = '__root__';
551
551
 
552
552
  // The parse type here allows a zod schema to be passed directly to the validator
553
553
 
554
+ // T extends Record<PropertyKey, infer U>
555
+ // ? {
556
+ // [K in keyof T]: UseLoaderResultPromise<T[K]>
557
+ // }
558
+ // : UseLoaderResultPromise<T>
559
+
560
+ // export type UseLoaderResultPromise<T> = T extends Promise<infer U>
561
+ // ? StreamedPromise<U>
562
+ // : T
554
563
  class Route {
555
564
  // Set up in this.init()
556
565
 
@@ -813,7 +822,7 @@ class Router {
813
822
  } = this.options;
814
823
  this.basepath = `/${trimPath(basepath ?? '') ?? ''}`;
815
824
  if (routeTree && routeTree !== this.routeTree) {
816
- this.#buildRouteTree(routeTree);
825
+ this.#processRoutes(routeTree);
817
826
  }
818
827
  return this;
819
828
  };
@@ -1049,8 +1058,8 @@ class Router {
1049
1058
  params: routeParams,
1050
1059
  pathname: joinPaths([this.basepath, interpolatedPath]),
1051
1060
  updatedAt: Date.now(),
1052
- invalidAt: Infinity,
1053
- preloadInvalidAt: Infinity,
1061
+ invalidAt: 9999999999999,
1062
+ preloadInvalidAt: 9999999999999,
1054
1063
  routeSearch: {},
1055
1064
  search: {},
1056
1065
  status: hasLoaders ? 'pending' : 'success',
@@ -1464,7 +1473,9 @@ class Router {
1464
1473
  };
1465
1474
  dehydrate = () => {
1466
1475
  return {
1467
- state: pick(this.state, ['location', 'status', 'lastUpdated'])
1476
+ state: {
1477
+ dehydratedMatches: this.state.matches.map(d => pick(d, ['fetchedAt', 'invalid', 'invalidAt', 'id', 'loaderData', 'status', 'updatedAt']))
1478
+ }
1468
1479
  };
1469
1480
  };
1470
1481
  hydrate = async __do_not_use_server_ctx => {
@@ -1477,16 +1488,27 @@ class Router {
1477
1488
  const ctx = _ctx;
1478
1489
  this.dehydratedData = ctx.payload;
1479
1490
  this.options.hydrate?.(ctx.payload);
1480
- const routerState = ctx.router.state;
1491
+ const {
1492
+ dehydratedMatches
1493
+ } = ctx.router.state;
1494
+ let matches = this.matchRoutes(this.state.location.pathname, this.state.location.search).map(match => {
1495
+ const dehydratedMatch = dehydratedMatches.find(d => d.id === match.id);
1496
+ invariant(dehydratedMatch, `Could not find a client-side match for dehydrated match with id: ${match.id}!`);
1497
+ if (dehydratedMatch) {
1498
+ return {
1499
+ ...match,
1500
+ ...dehydratedMatch
1501
+ };
1502
+ }
1503
+ return match;
1504
+ });
1481
1505
  this.__store.setState(s => {
1482
1506
  return {
1483
1507
  ...s,
1484
- ...routerState,
1485
- resolvedLocation: routerState.location
1508
+ matches,
1509
+ matchesById: this.#mergeMatches(s.matchesById, matches)
1486
1510
  };
1487
1511
  });
1488
- await this.load();
1489
- return;
1490
1512
  };
1491
1513
  injectedHtml = [];
1492
1514
  injectHtml = async html => {
@@ -1499,10 +1521,10 @@ class Router {
1499
1521
  const id = `__TSR_DEHYDRATED__${strKey}`;
1500
1522
  const data = typeof getData === 'function' ? await getData() : getData;
1501
1523
  return `<script id='${id}' suppressHydrationWarning>window["__TSR_DEHYDRATED__${escapeJSON(strKey)}"] = ${JSON.stringify(data)}
1502
- ;(() => {
1503
- var el = document.getElementById('${id}')
1504
- el.parentElement.removeChild(el)
1505
- })()
1524
+ // ;(() => {
1525
+ // var el = document.getElementById('${id}')
1526
+ // el.parentElement.removeChild(el)
1527
+ // })()
1506
1528
  </script>`;
1507
1529
  });
1508
1530
  return () => this.hydrateData(key);
@@ -1523,7 +1545,7 @@ class Router {
1523
1545
  // ?.__promisesByKey[key]?.resolve(value)
1524
1546
  // }
1525
1547
 
1526
- #buildRouteTree = routeTree => {
1548
+ #processRoutes = routeTree => {
1527
1549
  this.routeTree = routeTree;
1528
1550
  this.routesById = {};
1529
1551
  this.routesByPath = {};
@@ -1715,7 +1737,7 @@ class Router {
1715
1737
  const route = this.getRoute(match.routeId);
1716
1738
  const updatedAt = opts?.updatedAt ?? Date.now();
1717
1739
  const preloadInvalidAt = updatedAt + (opts?.maxAge ?? route.options.preloadMaxAge ?? this.options.defaultPreloadMaxAge ?? 5000);
1718
- const invalidAt = updatedAt + (opts?.maxAge ?? route.options.maxAge ?? this.options.defaultMaxAge ?? Infinity);
1740
+ const invalidAt = updatedAt + (opts?.maxAge ?? route.options.maxAge ?? this.options.defaultMaxAge ?? 9999999999999);
1719
1741
  this.setRouteMatch(id, s => ({
1720
1742
  ...s,
1721
1743
  error: undefined,
@@ -1935,5 +1957,27 @@ function restoreScrollPositions(router, opts) {
1935
1957
  }
1936
1958
  }
1937
1959
 
1938
- export { FileRoute, PathParamError, RootRoute, Route, Router, RouterContext, SearchParamError, cleanPath, componentTypes, createBrowserHistory, createHashHistory, createMemoryHistory, decode, defaultParseSearch, defaultStringifySearch, encode, functionalUpdate, interpolatePath, isPlainObject, isRedirect, joinPaths, last, lazyFn, matchByPath, matchPathname, parsePathname, parseSearchWith, partialDeepEqual, pick, redirect, replaceEqualDeep, resolvePath, restoreScrollPositions, rootRouteId, stringifySearchWith, trimPath, trimPathLeft, trimPathRight, watchScrollPositions };
1960
+ function defer(_promise) {
1961
+ const promise = _promise;
1962
+ if (!promise.__deferredState) {
1963
+ promise.__deferredState = {
1964
+ uid: Math.random().toString(36).slice(2),
1965
+ status: 'pending'
1966
+ };
1967
+ const state = promise.__deferredState;
1968
+ promise.then(data => {
1969
+ state.status = 'success';
1970
+ state.data = data;
1971
+ }).catch(error => {
1972
+ state.status = 'error';
1973
+ state.error = error;
1974
+ });
1975
+ }
1976
+ return promise;
1977
+ }
1978
+ function isDehydratedDeferred(obj) {
1979
+ return typeof obj === 'object' && obj !== null && !(obj instanceof Promise) && !obj.then && '__deferredState' in obj;
1980
+ }
1981
+
1982
+ export { FileRoute, PathParamError, RootRoute, Route, Router, RouterContext, SearchParamError, cleanPath, componentTypes, createBrowserHistory, createHashHistory, createMemoryHistory, decode, defaultParseSearch, defaultStringifySearch, defer, encode, functionalUpdate, interpolatePath, isDehydratedDeferred, isPlainObject, isRedirect, joinPaths, last, lazyFn, matchByPath, matchPathname, parsePathname, parseSearchWith, partialDeepEqual, pick, redirect, replaceEqualDeep, resolvePath, restoreScrollPositions, rootRouteId, stringifySearchWith, trimPath, trimPathLeft, trimPathRight, watchScrollPositions };
1939
1983
  //# sourceMappingURL=index.js.map