@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.
@@ -188,9 +188,9 @@ interface RouterOptions<TRouteTree extends AnyRoute, TDehydrated extends Record<
188
188
  parseSearch?: SearchParser;
189
189
  defaultPreload?: false | 'intent';
190
190
  defaultPreloadDelay?: number;
191
- defaultComponent?: RegisteredRouteComponent<RouteProps<unknown, AnySearchSchema, AnyPathParams, AnyContext, AnyContext>>;
192
- defaultErrorComponent?: RegisteredRouteErrorComponent<ErrorRouteProps<AnySearchSchema, AnyPathParams, AnyContext, AnyContext>>;
193
- defaultPendingComponent?: RegisteredRouteComponent<RouteProps<unknown, AnySearchSchema, AnyPathParams, AnyContext, AnyContext>>;
191
+ defaultComponent?: RegisteredRouteComponent<unknown, AnySearchSchema, AnyPathParams, AnyContext, AnyContext>;
192
+ defaultErrorComponent?: RegisteredErrorRouteComponent<AnySearchSchema, AnyPathParams, AnyContext, AnyContext>;
193
+ defaultPendingComponent?: RegisteredPendingRouteComponent<AnySearchSchema, AnyPathParams, AnyContext, AnyContext>;
194
194
  defaultMaxAge?: number;
195
195
  defaultGcMaxAge?: number;
196
196
  defaultPreloadMaxAge?: number;
@@ -246,8 +246,10 @@ interface MatchRouteOptions {
246
246
  includeSearch?: boolean;
247
247
  fuzzy?: boolean;
248
248
  }
249
- interface DehydratedRouterState extends Pick<RouterState, 'status' | 'location' | 'lastUpdated'> {
249
+ interface DehydratedRouterState {
250
+ dehydratedMatches: DehydratedRouteMatch[];
250
251
  }
252
+ type DehydratedRouteMatch = Pick<RouteMatch, 'fetchedAt' | 'invalid' | 'invalidAt' | 'id' | 'loaderData' | 'status' | 'updatedAt'>;
251
253
  interface DehydratedRouter {
252
254
  state: DehydratedRouterState;
253
255
  }
@@ -306,6 +308,7 @@ declare class Router<TRouteTree extends AnyRoute = AnyRoute, TDehydrated extends
306
308
  load: (opts?: {
307
309
  next?: ParsedLocation;
308
310
  throwOnError?: boolean;
311
+ __dehydratedMatches?: DehydratedRouteMatch[];
309
312
  }) => Promise<void>;
310
313
  getRoute: (id: string) => Route;
311
314
  preloadRoute: (navigateOpts?: BuildNextOptions & {
@@ -367,16 +370,36 @@ interface RouteMeta {
367
370
  }
368
371
  interface RouteContext {
369
372
  }
370
- interface RegisterRouteComponent<TProps> {
373
+ interface RegisterRouteComponent<TLoader = unknown, TFullSearchSchema extends AnySearchSchema = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TRouteContext extends AnyContext = AnyContext, TAllContext extends AnyContext = AnyContext> {
371
374
  }
372
- interface RegisterRouteErrorComponent<TProps> {
375
+ interface RegisterErrorRouteComponent<TFullSearchSchema extends AnySearchSchema = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TRouteContext extends AnyContext = AnyContext, TAllContext extends AnyContext = AnyContext> {
373
376
  }
374
- type RegisteredRouteComponent<TProps> = RegisterRouteComponent<TProps> extends {
377
+ interface RegisterPendingRouteComponent<TFullSearchSchema extends AnySearchSchema = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TRouteContext extends AnyContext = AnyContext, TAllContext extends AnyContext = AnyContext> {
378
+ }
379
+ interface RegisterRouteProps<TLoader = unknown, TFullSearchSchema extends AnySearchSchema = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TRouteContext extends AnyContext = AnyContext, TAllContext extends AnyContext = AnyContext> {
380
+ }
381
+ interface RegisterErrorRouteProps<TFullSearchSchema extends AnySearchSchema = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TRouteContext extends AnyContext = AnyContext, TAllContext extends AnyContext = AnyContext> {
382
+ }
383
+ interface RegisterPendingRouteProps<TFullSearchSchema extends AnySearchSchema = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TRouteContext extends AnyContext = AnyContext, TAllContext extends AnyContext = AnyContext> {
384
+ }
385
+ type RegisteredRouteComponent<TLoader = unknown, TFullSearchSchema extends AnySearchSchema = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TRouteContext extends AnyContext = AnyContext, TAllContext extends AnyContext = AnyContext> = RegisterRouteComponent<TLoader, TFullSearchSchema, TAllParams, TRouteContext, TAllContext> extends {
375
386
  RouteComponent: infer T;
376
- } ? T : (props: TProps) => unknown;
377
- type RegisteredRouteErrorComponent<TProps> = RegisterRouteErrorComponent<TProps> extends {
378
- RouteErrorComponent: infer T;
379
- } ? T : (props: TProps) => unknown;
387
+ } ? T : () => unknown;
388
+ type RegisteredErrorRouteComponent<TFullSearchSchema extends AnySearchSchema = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TRouteContext extends AnyContext = AnyContext, TAllContext extends AnyContext = AnyContext> = RegisterErrorRouteComponent<TFullSearchSchema, TAllParams, TRouteContext, TAllContext> extends {
389
+ ErrorRouteComponent: infer T;
390
+ } ? T : () => unknown;
391
+ type RegisteredPendingRouteComponent<TFullSearchSchema extends AnySearchSchema = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TRouteContext extends AnyContext = AnyContext, TAllContext extends AnyContext = AnyContext> = RegisterPendingRouteComponent<TFullSearchSchema, TAllParams, TRouteContext, TAllContext> extends {
392
+ PendingRouteComponent: infer T;
393
+ } ? T : () => unknown;
394
+ type RegisteredRouteProps<TLoader = unknown, TFullSearchSchema extends AnySearchSchema = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TRouteContext extends AnyContext = AnyContext, TAllContext extends AnyContext = AnyContext> = RegisterRouteProps<TLoader, TFullSearchSchema, TAllParams, TRouteContext, TAllContext> extends {
395
+ RouteProps: infer T;
396
+ } ? T : {};
397
+ type RegisteredErrorRouteProps<TFullSearchSchema extends AnySearchSchema = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TRouteContext extends AnyContext = AnyContext, TAllContext extends AnyContext = AnyContext> = RegisterRouteProps<TFullSearchSchema, TAllParams, TRouteContext, TAllContext> extends {
398
+ ErrorRouteProps: infer T;
399
+ } ? T : {};
400
+ type RegisteredPendingRouteProps<TFullSearchSchema extends AnySearchSchema = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TRouteContext extends AnyContext = AnyContext, TAllContext extends AnyContext = AnyContext> = RegisterRouteProps<TFullSearchSchema, TAllParams, TRouteContext, TAllContext> extends {
401
+ PendingRouteProps: infer T;
402
+ } ? T : {};
380
403
  type PreloadableObj = {
381
404
  preload?: () => Promise<void>;
382
405
  };
@@ -391,31 +414,10 @@ type MetaOptions = keyof PickRequired<RouteMeta> extends never ? {
391
414
  } : {
392
415
  meta: RouteMeta;
393
416
  };
394
- type AnyRouteProps = RouteProps<any, any, any, any, any>;
395
- type ComponentPropsFromRoute<TRoute> = TRoute extends Route<infer TParentRoute, infer TPath, infer TFullPath, infer TCustomId, infer TId, infer TLoader, infer TSearchSchema, infer TFullSearchSchema, infer TParams, infer TAllParams, infer TParentContext, infer TAllParentContext, infer TRouteContext, infer TContext, infer TRouterContext, infer TChildren, infer TRouteTree> ? RouteProps<TLoader, TFullSearchSchema, TAllParams, TRouteContext, TContext> : never;
417
+ type AnyRouteProps = RegisteredRouteProps<any, any, any, any, any>;
418
+ type ComponentPropsFromRoute<TRoute> = TRoute extends Route<infer TParentRoute, infer TPath, infer TFullPath, infer TCustomId, infer TId, infer TLoader, infer TSearchSchema, infer TFullSearchSchema, infer TParams, infer TAllParams, infer TParentContext, infer TAllParentContext, infer TRouteContext, infer TContext, infer TRouterContext, infer TChildren, infer TRouteTree> ? RegisteredRouteProps<TLoader, TFullSearchSchema, TAllParams, TRouteContext, TContext> : never;
396
419
  type ComponentFromRoute<TRoute> = RegisteredRouteComponent<ComponentPropsFromRoute<TRoute>>;
397
420
  type RouteLoaderFromRoute<TRoute extends AnyRoute> = LoaderFn<TRoute['types']['loader'], TRoute['types']['searchSchema'], TRoute['types']['fullSearchSchema'], TRoute['types']['allParams'], TRoute['types']['routeContext'], TRoute['types']['context']>;
398
- type RouteProps<TLoader extends any = unknown, TFullSearchSchema extends AnySearchSchema = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TRouteContext extends AnyContext = AnyContext, TContext extends AnyContext = AnyContext> = {
399
- useMatch: () => RouteMatch<any, any>;
400
- useLoader: () => UseLoaderResult<TLoader>;
401
- useSearch: <TStrict extends boolean = true, TSearch = TFullSearchSchema, TSelected = TSearch>(opts?: {
402
- strict?: TStrict;
403
- select?: (search: TSearch) => TSelected;
404
- }) => TStrict extends true ? TSelected : TSelected | undefined;
405
- useParams: <TDefaultSelected = TAllParams, TSelected = TDefaultSelected>(opts?: {
406
- select?: (params: TDefaultSelected) => TSelected;
407
- }) => TSelected;
408
- useContext: <TDefaultSelected = TContext, TSelected = TDefaultSelected>(opts?: {
409
- select?: (context: TDefaultSelected) => TSelected;
410
- }) => TSelected;
411
- useRouteContext: <TDefaultSelected = TRouteContext, TSelected = TDefaultSelected>(opts?: {
412
- select?: (context: TDefaultSelected) => TSelected;
413
- }) => TSelected;
414
- };
415
- type PendingRouteProps<TFullSearchSchema extends AnySearchSchema = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TRouteContext extends AnyContext = AnyContext, TContext extends AnyContext = AnyContext> = Omit<RouteProps<any, TFullSearchSchema, TAllParams, TRouteContext, TContext>, 'useLoader'>;
416
- type ErrorRouteProps<TFullSearchSchema extends AnySearchSchema = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TRouteContext extends AnyContext = AnyContext, TContext extends AnyContext = AnyContext> = PendingRouteProps<TFullSearchSchema, TAllParams, TRouteContext, TContext> & {
417
- error: unknown;
418
- };
419
421
  type RouteOptions<TParentRoute extends AnyRoute = AnyRoute, TCustomId extends string = string, TPath extends string = string, TLoader = unknown, TParentSearchSchema extends AnySearchSchema = {}, TSearchSchema extends AnySearchSchema = {}, TFullSearchSchema extends AnySearchSchema = TSearchSchema, TParams extends AnyPathParams = AnyPathParams, TAllParams extends AnyPathParams = TParams, TParentContext extends AnyContext = AnyContext, TAllParentContext extends AnyContext = AnyContext, TRouteContext extends RouteContext = RouteContext, TAllContext extends AnyContext = AnyContext> = BaseRouteOptions<TParentRoute, TCustomId, TPath, TLoader, TParentSearchSchema, TSearchSchema, TFullSearchSchema, TParams, TAllParams, TParentContext, TAllParentContext, TRouteContext, TAllContext> & UpdatableRouteOptions<TLoader, TSearchSchema, TFullSearchSchema, TAllParams, TRouteContext, TAllContext>;
420
422
  type ParamsFallback<TPath extends string, TParams> = unknown extends TParams ? Record<ParsePathParams<TPath>, string> : TParams;
421
423
  type BaseRouteOptions<TParentRoute extends AnyRoute = AnyRoute, TCustomId extends string = string, TPath extends string = string, TLoader = unknown, TParentSearchSchema extends AnySearchSchema = {}, TSearchSchema extends AnySearchSchema = {}, TFullSearchSchema extends AnySearchSchema = TSearchSchema, TParams extends AnyPathParams = {}, TAllParams = ParamsFallback<TPath, TParams>, TParentContext extends AnyContext = AnyContext, TAllParentContext extends AnyContext = AnyContext, TRouteContext extends RouteContext = RouteContext, TAllContext extends AnyContext = AnyContext> = RoutePathOptions<TCustomId, TPath> & {
@@ -446,19 +448,19 @@ type GetContextFn<TParentRoute, TAllParams, TFullSearchSchema, TParentContext, T
446
448
  context: TAllParentContext;
447
449
  parentContext: TParentContext;
448
450
  })) => TRouteContext;
449
- type UpdatableRouteOptions<TLoader, TSearchSchema extends AnySearchSchema, TFullSearchSchema extends AnySearchSchema, TAllParams extends AnyPathParams, TRouteContext extends AnyContext, TContext extends AnyContext> = MetaOptions & {
451
+ type UpdatableRouteOptions<TLoader, TSearchSchema extends AnySearchSchema, TFullSearchSchema extends AnySearchSchema, TAllParams extends AnyPathParams, TRouteContext extends AnyContext, TAllContext extends AnyContext> = MetaOptions & {
450
452
  key?: null | false | GetKeyFn<TFullSearchSchema, TAllParams>;
451
453
  caseSensitive?: boolean;
452
454
  wrapInSuspense?: boolean;
453
- component?: RegisteredRouteComponent<RouteProps<TLoader, TFullSearchSchema, TAllParams, TRouteContext, TContext>>;
454
- errorComponent?: RegisteredRouteErrorComponent<ErrorRouteProps<TFullSearchSchema, TAllParams, TRouteContext, TContext>>;
455
- pendingComponent?: RegisteredRouteComponent<PendingRouteProps<TFullSearchSchema, TAllParams, TRouteContext, TContext>>;
455
+ component?: RegisteredRouteComponent<TLoader, TFullSearchSchema, TAllParams, TRouteContext, TAllContext>;
456
+ errorComponent?: RegisteredErrorRouteComponent<TFullSearchSchema, TAllParams, TRouteContext, TAllContext>;
457
+ pendingComponent?: RegisteredPendingRouteComponent<TFullSearchSchema, TAllParams, TRouteContext, TAllContext>;
456
458
  preSearchFilters?: SearchFilter<TFullSearchSchema>[];
457
459
  postSearchFilters?: SearchFilter<TFullSearchSchema>[];
458
460
  preloadMaxAge?: number;
459
461
  maxAge?: number;
460
462
  gcMaxAge?: number;
461
- beforeLoad?: (opts: LoaderContext<TSearchSchema, TFullSearchSchema, TAllParams, NoInfer<TRouteContext>, TContext>) => Promise<void> | void;
463
+ beforeLoad?: (opts: LoaderContext<TSearchSchema, TFullSearchSchema, TAllParams, NoInfer<TRouteContext>, TAllContext>) => Promise<void> | void;
462
464
  onError?: (err: any) => void;
463
465
  onLoaded?: (matchContext: {
464
466
  params: TAllParams;
@@ -521,10 +523,7 @@ type ResolveFullSearchSchema<TParentRoute, TSearchSchema> = InferFullSearchSchem
521
523
  interface AnyRoute extends Route<any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any> {
522
524
  }
523
525
  type MergeParamsFromParent<T, U> = IsAny<T, U, T & U>;
524
- type UseLoaderResult<T> = T extends Record<PropertyKey, infer U> ? {
525
- [K in keyof T]: UseLoaderResultPromise<T[K]>;
526
- } : UseLoaderResultPromise<T>;
527
- type UseLoaderResultPromise<T> = T extends Promise<infer U> ? StreamedPromise<U> : T;
526
+ type UseLoaderResult<T> = T;
528
527
  type StreamedPromise<T> = {
529
528
  promise: Promise<T>;
530
529
  status: 'resolved' | 'pending';
@@ -622,9 +621,9 @@ declare class FileRoute<TFilePath extends keyof FileRoutesByPath, TParentRoute e
622
621
  key?: false | GetKeyFn<TFullSearchSchema, TAllParams> | null | undefined;
623
622
  caseSensitive?: boolean | undefined;
624
623
  wrapInSuspense?: boolean | undefined;
625
- component?: ((props: RouteProps<TLoader, TFullSearchSchema, TAllParams, TRouteContext, TContext>) => unknown) | undefined;
626
- errorComponent?: ((props: ErrorRouteProps<TFullSearchSchema, TAllParams, TRouteContext, TContext>) => unknown) | undefined;
627
- pendingComponent?: ((props: PendingRouteProps<TFullSearchSchema, TAllParams, TRouteContext, TContext>) => unknown) | undefined;
624
+ component?: (() => unknown) | undefined;
625
+ errorComponent?: (() => unknown) | undefined;
626
+ pendingComponent?: (() => unknown) | undefined;
628
627
  preSearchFilters?: SearchFilter<TFullSearchSchema, TFullSearchSchema>[] | undefined;
629
628
  postSearchFilters?: SearchFilter<TFullSearchSchema, TFullSearchSchema>[] | undefined;
630
629
  preloadMaxAge?: number | undefined;
@@ -761,4 +760,24 @@ type ScrollRestorationOptions = {
761
760
  declare function watchScrollPositions(router: AnyRouter, opts?: ScrollRestorationOptions): () => void;
762
761
  declare function restoreScrollPositions(router: AnyRouter, opts?: ScrollRestorationOptions): void;
763
762
 
764
- export { ActiveOptions, AllParams, AnyContext, AnyPathParams, AnyRedirect, AnyRootRoute, AnyRoute, AnyRouteMatch, AnyRouteProps, AnyRouter, AnySearchSchema, BaseRouteOptions, BuildNextOptions, CheckId, CheckIdError, CheckPath, CheckPathError, CheckRelativePath, CleanPath, ComponentFromRoute, ComponentPropsFromRoute, DeepAwaited, DefinedPathParamWarning, DehydratedRouter, DehydratedRouterState, ErrorRouteProps, Expand, FileRoute, FileRoutePath, FileRoutesByPath, FromLocation, FullSearchSchema, GetKeyFn, HydrationCtx, InferFullSearchSchema, IsAny, IsAnyBoolean, IsKnown, Join, Last, LinkInfo, LinkOptions, ListenerFn, LoaderContext, LoaderFn, LocationState, MatchLocation, MatchRouteOptions, MergeParamsFromParent, MergeUnion, MetaOptions, NavigateOptions, NoInfer, ParamsFallback, ParentParams, ParseParamsFn, ParseParamsObj, ParseParamsOption, ParsePathParams, ParseRoute, ParseRouteChildren, ParsedLocation, ParsedPath, PathParamError, PathParamMask, PathParamOptions, PendingRouteProps, PickAsPartial, PickAsRequired, PickExclude, PickExtra, PickExtract, PickRequired, PickUnsafe, PreloadableObj, Redirect, Register, RegisterRouteComponent, RegisterRouteErrorComponent, RegisteredRouteComponent, RegisteredRouteErrorComponent, RegisteredRouter, RelativeToPathAutoComplete, RemoveUnderScores, ResolveFilePath, ResolveFullPath, ResolveFullSearchSchema, ResolveId, ResolveRelativePath, RootRoute, RootRouteId, Route, RouteById, RouteByPath, RouteConstraints, RouteContext, RouteIds, RouteLoaderFromRoute, RouteMatch, RouteMeta, RouteOptions, RoutePathOptions, RoutePathOptionsIntersection, RoutePaths, RouteProps, Router, RouterConstructorOptions, RouterContext, RouterContextOptions, RouterEvent, RouterEvents, RouterHistory, RouterListener, RouterLocation, RouterOptions, RouterState, RoutesById, RoutesByPath, ScrollRestorationOptions, SearchFilter, SearchParamError, SearchParamOptions, SearchParser, SearchSchemaValidator, SearchSchemaValidatorFn, SearchSchemaValidatorObj, SearchSerializer, Segment, Split, StreamedPromise, Timeout, ToIdOption, ToOptions, ToPathOption, Trim, TrimLeft, TrimPath, TrimPathLeft, TrimPathRight, TrimRight, UnionToIntersection, UnloaderFn, UpdatableRouteOptions, Updater, UseLoaderResult, UseLoaderResultPromise, ValueKeys, Values, 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 };
763
+ type DeferredPromiseState<T> = {
764
+ uid: string;
765
+ } & ({
766
+ status: 'pending';
767
+ data?: T;
768
+ error?: unknown;
769
+ } | {
770
+ status: 'success';
771
+ data: T;
772
+ } | {
773
+ status: 'error';
774
+ data?: T;
775
+ error: unknown;
776
+ });
777
+ type DeferredPromise<T> = Promise<T> & {
778
+ __deferredState: DeferredPromiseState<T>;
779
+ };
780
+ declare function defer<T>(_promise: Promise<T>): DeferredPromise<T>;
781
+ declare function isDehydratedDeferred(obj: any): boolean;
782
+
783
+ export { ActiveOptions, AllParams, AnyContext, AnyPathParams, AnyRedirect, AnyRootRoute, AnyRoute, AnyRouteMatch, AnyRouteProps, AnyRouter, AnySearchSchema, BaseRouteOptions, BuildNextOptions, CheckId, CheckIdError, CheckPath, CheckPathError, CheckRelativePath, CleanPath, ComponentFromRoute, ComponentPropsFromRoute, DeepAwaited, DeferredPromise, DeferredPromiseState, DefinedPathParamWarning, DehydratedRouteMatch, DehydratedRouter, DehydratedRouterState, Expand, FileRoute, FileRoutePath, FileRoutesByPath, FromLocation, FullSearchSchema, GetKeyFn, HydrationCtx, InferFullSearchSchema, IsAny, IsAnyBoolean, IsKnown, Join, Last, LinkInfo, LinkOptions, ListenerFn, LoaderContext, LoaderFn, LocationState, MatchLocation, MatchRouteOptions, MergeParamsFromParent, MergeUnion, MetaOptions, NavigateOptions, NoInfer, ParamsFallback, ParentParams, ParseParamsFn, ParseParamsObj, ParseParamsOption, ParsePathParams, ParseRoute, ParseRouteChildren, ParsedLocation, ParsedPath, PathParamError, PathParamMask, PathParamOptions, PickAsPartial, PickAsRequired, PickExclude, PickExtra, PickExtract, PickRequired, PickUnsafe, PreloadableObj, Redirect, Register, RegisterErrorRouteComponent, RegisterErrorRouteProps, RegisterPendingRouteComponent, RegisterPendingRouteProps, RegisterRouteComponent, RegisterRouteProps, RegisteredErrorRouteComponent, RegisteredErrorRouteProps, RegisteredPendingRouteComponent, RegisteredPendingRouteProps, RegisteredRouteComponent, RegisteredRouteProps, RegisteredRouter, RelativeToPathAutoComplete, RemoveUnderScores, ResolveFilePath, ResolveFullPath, ResolveFullSearchSchema, ResolveId, ResolveRelativePath, RootRoute, RootRouteId, Route, RouteById, RouteByPath, RouteConstraints, RouteContext, RouteIds, RouteLoaderFromRoute, RouteMatch, RouteMeta, RouteOptions, RoutePathOptions, RoutePathOptionsIntersection, RoutePaths, Router, RouterConstructorOptions, RouterContext, RouterContextOptions, RouterEvent, RouterEvents, RouterHistory, RouterListener, RouterLocation, RouterOptions, RouterState, RoutesById, RoutesByPath, ScrollRestorationOptions, SearchFilter, SearchParamError, SearchParamOptions, SearchParser, SearchSchemaValidator, SearchSchemaValidatorFn, SearchSchemaValidatorObj, SearchSerializer, Segment, Split, StreamedPromise, Timeout, ToIdOption, ToOptions, ToPathOption, Trim, TrimLeft, TrimPath, TrimPathLeft, TrimPathRight, TrimRight, UnionToIntersection, UnloaderFn, UpdatableRouteOptions, Updater, UseLoaderResult, ValueKeys, Values, 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 };
@@ -580,6 +580,15 @@
580
580
 
581
581
  // The parse type here allows a zod schema to be passed directly to the validator
582
582
 
583
+ // T extends Record<PropertyKey, infer U>
584
+ // ? {
585
+ // [K in keyof T]: UseLoaderResultPromise<T[K]>
586
+ // }
587
+ // : UseLoaderResultPromise<T>
588
+
589
+ // export type UseLoaderResultPromise<T> = T extends Promise<infer U>
590
+ // ? StreamedPromise<U>
591
+ // : T
583
592
  class Route {
584
593
  // Set up in this.init()
585
594
 
@@ -908,7 +917,7 @@
908
917
  } = this.options;
909
918
  this.basepath = `/${trimPath(basepath ?? '') ?? ''}`;
910
919
  if (routeTree && routeTree !== this.routeTree) {
911
- this.#buildRouteTree(routeTree);
920
+ this.#processRoutes(routeTree);
912
921
  }
913
922
  return this;
914
923
  };
@@ -1228,7 +1237,6 @@
1228
1237
  return matches;
1229
1238
  };
1230
1239
  loadMatches = async (resolvedMatches, opts) => {
1231
- this.cleanMatches();
1232
1240
  if (!opts?.preload) {
1233
1241
  resolvedMatches.forEach(match => {
1234
1242
  // Update each match with its latest route data
@@ -1241,10 +1249,12 @@
1241
1249
  error: match.error,
1242
1250
  paramsError: match.paramsError,
1243
1251
  searchError: match.searchError,
1244
- params: match.params
1252
+ params: match.params,
1253
+ preloadInvalidAt: 0
1245
1254
  }));
1246
1255
  });
1247
1256
  }
1257
+ this.cleanMatches();
1248
1258
  let firstBadMatchIndex;
1249
1259
 
1250
1260
  // Check each match middleware to see if the route can be accessed
@@ -1380,6 +1390,7 @@
1380
1390
  })());
1381
1391
  });
1382
1392
  await Promise.all(matchPromises);
1393
+ this.cleanMatches();
1383
1394
  };
1384
1395
  reload = () => {
1385
1396
  return this.navigate({
@@ -1559,7 +1570,9 @@
1559
1570
  };
1560
1571
  dehydrate = () => {
1561
1572
  return {
1562
- state: pick(this.state, ['location', 'status', 'lastUpdated'])
1573
+ state: {
1574
+ dehydratedMatches: this.state.matches.map(d => pick(d, ['fetchedAt', 'invalid', 'invalidAt', 'id', 'loaderData', 'status', 'updatedAt']))
1575
+ }
1563
1576
  };
1564
1577
  };
1565
1578
  hydrate = async __do_not_use_server_ctx => {
@@ -1572,16 +1585,27 @@
1572
1585
  const ctx = _ctx;
1573
1586
  this.dehydratedData = ctx.payload;
1574
1587
  this.options.hydrate?.(ctx.payload);
1575
- const routerState = ctx.router.state;
1588
+ const {
1589
+ dehydratedMatches
1590
+ } = ctx.router.state;
1591
+ let matches = this.matchRoutes(this.state.location.pathname, this.state.location.search).map(match => {
1592
+ const dehydratedMatch = dehydratedMatches.find(d => d.id === match.id);
1593
+ invariant(dehydratedMatch, `Could not find a client-side match for dehydrated match with id: ${match.id}!`);
1594
+ if (dehydratedMatch) {
1595
+ return {
1596
+ ...match,
1597
+ ...dehydratedMatch
1598
+ };
1599
+ }
1600
+ return match;
1601
+ });
1576
1602
  this.__store.setState(s => {
1577
1603
  return {
1578
1604
  ...s,
1579
- ...routerState,
1580
- resolvedLocation: routerState.location
1605
+ matches,
1606
+ matchesById: this.#mergeMatches(s.matchesById, matches)
1581
1607
  };
1582
1608
  });
1583
- await this.load();
1584
- return;
1585
1609
  };
1586
1610
  injectedHtml = [];
1587
1611
  injectHtml = async html => {
@@ -1594,10 +1618,10 @@
1594
1618
  const id = `__TSR_DEHYDRATED__${strKey}`;
1595
1619
  const data = typeof getData === 'function' ? await getData() : getData;
1596
1620
  return `<script id='${id}' suppressHydrationWarning>window["__TSR_DEHYDRATED__${escapeJSON(strKey)}"] = ${JSON.stringify(data)}
1597
- ;(() => {
1598
- var el = document.getElementById('${id}')
1599
- el.parentElement.removeChild(el)
1600
- })()
1621
+ // ;(() => {
1622
+ // var el = document.getElementById('${id}')
1623
+ // el.parentElement.removeChild(el)
1624
+ // })()
1601
1625
  </script>`;
1602
1626
  });
1603
1627
  return () => this.hydrateData(key);
@@ -1618,7 +1642,7 @@
1618
1642
  // ?.__promisesByKey[key]?.resolve(value)
1619
1643
  // }
1620
1644
 
1621
- #buildRouteTree = routeTree => {
1645
+ #processRoutes = routeTree => {
1622
1646
  this.routeTree = routeTree;
1623
1647
  this.routesById = {};
1624
1648
  this.routesByPath = {};
@@ -1821,7 +1845,6 @@
1821
1845
  preloadInvalidAt,
1822
1846
  invalidAt
1823
1847
  }));
1824
- if (this.state.matches.find(d => d.id === id)) ;
1825
1848
  };
1826
1849
  invalidate = async opts => {
1827
1850
  if (opts?.matchId) {
@@ -2030,6 +2053,28 @@
2030
2053
  }
2031
2054
  }
2032
2055
 
2056
+ function defer(_promise) {
2057
+ const promise = _promise;
2058
+ if (!promise.__deferredState) {
2059
+ promise.__deferredState = {
2060
+ uid: Math.random().toString(36).slice(2),
2061
+ status: 'pending'
2062
+ };
2063
+ const state = promise.__deferredState;
2064
+ promise.then(data => {
2065
+ state.status = 'success';
2066
+ state.data = data;
2067
+ }).catch(error => {
2068
+ state.status = 'error';
2069
+ state.error = error;
2070
+ });
2071
+ }
2072
+ return promise;
2073
+ }
2074
+ function isDehydratedDeferred(obj) {
2075
+ return typeof obj === 'object' && obj !== null && !(obj instanceof Promise) && !obj.then && '__deferredState' in obj;
2076
+ }
2077
+
2033
2078
  exports.FileRoute = FileRoute;
2034
2079
  exports.PathParamError = PathParamError;
2035
2080
  exports.RootRoute = RootRoute;
@@ -2045,10 +2090,12 @@
2045
2090
  exports.decode = decode;
2046
2091
  exports.defaultParseSearch = defaultParseSearch;
2047
2092
  exports.defaultStringifySearch = defaultStringifySearch;
2093
+ exports.defer = defer;
2048
2094
  exports.encode = encode;
2049
2095
  exports.functionalUpdate = functionalUpdate;
2050
2096
  exports.interpolatePath = interpolatePath;
2051
2097
  exports.invariant = invariant;
2098
+ exports.isDehydratedDeferred = isDehydratedDeferred;
2052
2099
  exports.isPlainObject = isPlainObject;
2053
2100
  exports.isRedirect = isRedirect;
2054
2101
  exports.joinPaths = joinPaths;