@tanstack/router-core 0.0.1-beta.50 → 0.0.1-beta.51

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.
@@ -133,7 +133,7 @@ interface RouterOptions<TRouteConfig extends AnyRouteConfig, TRouterContext> {
133
133
  routeConfig?: TRouteConfig;
134
134
  basepath?: string;
135
135
  useServerData?: boolean;
136
- createRouter?: (router: AnyRouter) => void;
136
+ Router?: (router: AnyRouter) => void;
137
137
  createRoute?: (opts: {
138
138
  route: AnyRoute;
139
139
  router: AnyRouter;
@@ -221,7 +221,7 @@ interface DehydratedRouter<TRouterContext = unknown> {
221
221
  }
222
222
  type MatchCache = Record<string, MatchCacheEntry>;
223
223
  interface DehydratedRouteMatch {
224
- matchId: string;
224
+ id: string;
225
225
  state: Pick<RouteMatchStore<any, any>, 'status' | 'routeLoaderData' | 'invalid' | 'invalidAt'>;
226
226
  }
227
227
  interface RouterContext {
@@ -316,7 +316,7 @@ declare class RouteMatch<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRoute
316
316
  search: TRouteInfo['fullSearchSchema'];
317
317
  }) => void);
318
318
  constructor(router: AnyRouter, route: Route<TAllRouteInfo, TRouteInfo>, opts: {
319
- matchId: string;
319
+ id: string;
320
320
  params: TRouteInfo['allParams'];
321
321
  pathname: string;
322
322
  });
@@ -678,7 +678,7 @@
678
678
  Object.assign(this, {
679
679
  route,
680
680
  router,
681
- matchId: opts.matchId,
681
+ id: opts.id,
682
682
  pathname: opts.pathname,
683
683
  params: opts.params,
684
684
  store: createStore({
@@ -972,13 +972,12 @@
972
972
  parseSearch: options?.parseSearch ?? defaultParseSearch,
973
973
  fetchServerDataFn: options?.fetchServerDataFn ?? defaultFetchServerDataFn
974
974
  };
975
- this.history = this.options?.history ?? createBrowserHistory();
976
975
  this.store = createStore(getInitialRouterState());
977
976
  this.basepath = '';
978
977
  this.update(options);
979
978
 
980
979
  // Allow frameworks to hook into the router creation
981
- this.options.createRouter?.(this);
980
+ this.options.Router?.(this);
982
981
  }
983
982
  reset = () => {
984
983
  this.store.setState(s => Object.assign(s, getInitialRouterState()));
@@ -1017,13 +1016,14 @@
1017
1016
  return () => {};
1018
1017
  };
1019
1018
  update = opts => {
1020
- if (!this.store.state.latestLocation) {
1019
+ Object.assign(this.options, opts);
1020
+ if (!this.history || this.options.history && this.options.history !== this.history) {
1021
+ this.history = this.options?.history ?? isServer ? createMemoryHistory() : createBrowserHistory();
1021
1022
  this.store.setState(s => {
1022
1023
  s.latestLocation = this.#parseLocation();
1023
1024
  s.currentLocation = s.latestLocation;
1024
1025
  });
1025
1026
  }
1026
- Object.assign(this.options, opts);
1027
1027
  const {
1028
1028
  basepath,
1029
1029
  routeConfig
@@ -1248,7 +1248,7 @@
1248
1248
  const interpolatedPath = interpolatePath(foundRoute.path, params);
1249
1249
  const matchId = interpolatePath(foundRoute.id, params, true);
1250
1250
  const match = existingMatches.find(d => d.id === matchId) || this.store.state.matchCache[matchId]?.match || new RouteMatch(this, foundRoute, {
1251
- matchId,
1251
+ id: matchId,
1252
1252
  params,
1253
1253
  pathname: joinPaths([this.basepath, interpolatedPath])
1254
1254
  });
@@ -1320,10 +1320,11 @@
1320
1320
 
1321
1321
  // TODO: batch requests when possible
1322
1322
 
1323
- return this.options.fetchServerDataFn({
1323
+ const res = await this.options.fetchServerDataFn({
1324
1324
  router: this,
1325
1325
  routeMatch
1326
1326
  });
1327
+ return res;
1327
1328
  }
1328
1329
  };
1329
1330
  invalidateRoute = async opts => {
@@ -1514,7 +1515,7 @@
1514
1515
  state: {
1515
1516
  ...pick(this.store.state, ['latestLocation', 'currentLocation', 'status', 'lastUpdated']),
1516
1517
  currentMatches: this.store.state.currentMatches.map(match => ({
1517
- matchId: match.id,
1518
+ id: match.id,
1518
1519
  state: {
1519
1520
  ...pick(match.store.state, ['status', 'routeLoaderData', 'invalidAt', 'invalid'])
1520
1521
  }
@@ -1534,7 +1535,7 @@
1534
1535
  });
1535
1536
  currentMatches.forEach((match, index) => {
1536
1537
  const dehydratedMatch = dehydratedRouter.state.currentMatches[index];
1537
- invariant(dehydratedMatch && dehydratedMatch.matchId === match.id, 'Oh no! There was a hydration mismatch when attempting to rethis.store the state of the router! 😬');
1538
+ invariant(dehydratedMatch && dehydratedMatch.id === match.id, 'Oh no! There was a hydration mismatch when attempting to rethis.store the state of the router! 😬');
1538
1539
  Object.assign(match, dehydratedMatch);
1539
1540
  });
1540
1541
  currentMatches.forEach(match => match.__validate());
@@ -1681,7 +1682,9 @@
1681
1682
  id,
1682
1683
  ...next.state
1683
1684
  });
1684
- this.load(this.#parseLocation(this.store.state.latestLocation));
1685
+
1686
+ // this.load(this.#parseLocation(this.store.state.latestLocation))
1687
+
1685
1688
  return this.navigationPromise = new Promise(resolve => {
1686
1689
  const previousNavigationResolve = this.resolveNavigation;
1687
1690
  this.resolveNavigation = () => {
@@ -1723,7 +1726,7 @@
1723
1726
  });
1724
1727
  }
1725
1728
 
1726
- // createRouterAction is a constrained identify function that takes options: key, action, onSuccess, onError, onSettled, etc
1729
+ // RouterAction is a constrained identify function that takes options: key, action, onSuccess, onError, onSettled, etc
1727
1730
  function createAction(options) {
1728
1731
  const store = createStore({
1729
1732
  submissions: []