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

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
  };
@@ -1133,7 +1142,6 @@ class Router {
1133
1142
  return matches;
1134
1143
  };
1135
1144
  loadMatches = async (resolvedMatches, opts) => {
1136
- this.cleanMatches();
1137
1145
  if (!opts?.preload) {
1138
1146
  resolvedMatches.forEach(match => {
1139
1147
  // Update each match with its latest route data
@@ -1146,10 +1154,12 @@ class Router {
1146
1154
  error: match.error,
1147
1155
  paramsError: match.paramsError,
1148
1156
  searchError: match.searchError,
1149
- params: match.params
1157
+ params: match.params,
1158
+ preloadInvalidAt: 0
1150
1159
  }));
1151
1160
  });
1152
1161
  }
1162
+ this.cleanMatches();
1153
1163
  let firstBadMatchIndex;
1154
1164
 
1155
1165
  // Check each match middleware to see if the route can be accessed
@@ -1285,6 +1295,7 @@ class Router {
1285
1295
  })());
1286
1296
  });
1287
1297
  await Promise.all(matchPromises);
1298
+ this.cleanMatches();
1288
1299
  };
1289
1300
  reload = () => {
1290
1301
  return this.navigate({
@@ -1464,7 +1475,9 @@ class Router {
1464
1475
  };
1465
1476
  dehydrate = () => {
1466
1477
  return {
1467
- state: pick(this.state, ['location', 'status', 'lastUpdated'])
1478
+ state: {
1479
+ dehydratedMatches: this.state.matches.map(d => pick(d, ['fetchedAt', 'invalid', 'invalidAt', 'id', 'loaderData', 'status', 'updatedAt']))
1480
+ }
1468
1481
  };
1469
1482
  };
1470
1483
  hydrate = async __do_not_use_server_ctx => {
@@ -1477,16 +1490,27 @@ class Router {
1477
1490
  const ctx = _ctx;
1478
1491
  this.dehydratedData = ctx.payload;
1479
1492
  this.options.hydrate?.(ctx.payload);
1480
- const routerState = ctx.router.state;
1493
+ const {
1494
+ dehydratedMatches
1495
+ } = ctx.router.state;
1496
+ let matches = this.matchRoutes(this.state.location.pathname, this.state.location.search).map(match => {
1497
+ const dehydratedMatch = dehydratedMatches.find(d => d.id === match.id);
1498
+ invariant(dehydratedMatch, `Could not find a client-side match for dehydrated match with id: ${match.id}!`);
1499
+ if (dehydratedMatch) {
1500
+ return {
1501
+ ...match,
1502
+ ...dehydratedMatch
1503
+ };
1504
+ }
1505
+ return match;
1506
+ });
1481
1507
  this.__store.setState(s => {
1482
1508
  return {
1483
1509
  ...s,
1484
- ...routerState,
1485
- resolvedLocation: routerState.location
1510
+ matches,
1511
+ matchesById: this.#mergeMatches(s.matchesById, matches)
1486
1512
  };
1487
1513
  });
1488
- await this.load();
1489
- return;
1490
1514
  };
1491
1515
  injectedHtml = [];
1492
1516
  injectHtml = async html => {
@@ -1499,10 +1523,10 @@ class Router {
1499
1523
  const id = `__TSR_DEHYDRATED__${strKey}`;
1500
1524
  const data = typeof getData === 'function' ? await getData() : getData;
1501
1525
  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
- })()
1526
+ // ;(() => {
1527
+ // var el = document.getElementById('${id}')
1528
+ // el.parentElement.removeChild(el)
1529
+ // })()
1506
1530
  </script>`;
1507
1531
  });
1508
1532
  return () => this.hydrateData(key);
@@ -1523,7 +1547,7 @@ class Router {
1523
1547
  // ?.__promisesByKey[key]?.resolve(value)
1524
1548
  // }
1525
1549
 
1526
- #buildRouteTree = routeTree => {
1550
+ #processRoutes = routeTree => {
1527
1551
  this.routeTree = routeTree;
1528
1552
  this.routesById = {};
1529
1553
  this.routesByPath = {};
@@ -1726,7 +1750,6 @@ class Router {
1726
1750
  preloadInvalidAt,
1727
1751
  invalidAt
1728
1752
  }));
1729
- if (this.state.matches.find(d => d.id === id)) ;
1730
1753
  };
1731
1754
  invalidate = async opts => {
1732
1755
  if (opts?.matchId) {
@@ -1935,5 +1958,27 @@ function restoreScrollPositions(router, opts) {
1935
1958
  }
1936
1959
  }
1937
1960
 
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 };
1961
+ function defer(_promise) {
1962
+ const promise = _promise;
1963
+ if (!promise.__deferredState) {
1964
+ promise.__deferredState = {
1965
+ uid: Math.random().toString(36).slice(2),
1966
+ status: 'pending'
1967
+ };
1968
+ const state = promise.__deferredState;
1969
+ promise.then(data => {
1970
+ state.status = 'success';
1971
+ state.data = data;
1972
+ }).catch(error => {
1973
+ state.status = 'error';
1974
+ state.error = error;
1975
+ });
1976
+ }
1977
+ return promise;
1978
+ }
1979
+ function isDehydratedDeferred(obj) {
1980
+ return typeof obj === 'object' && obj !== null && !(obj instanceof Promise) && !obj.then && '__deferredState' in obj;
1981
+ }
1982
+
1983
+ 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
1984
  //# sourceMappingURL=index.js.map