@tanstack/react-router 1.12.15 → 1.13.0

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.
Files changed (54) hide show
  1. package/dist/cjs/Matches.d.cts +5 -5
  2. package/dist/cjs/RouterProvider.d.cts +6 -6
  3. package/dist/cjs/awaited.d.cts +1 -1
  4. package/dist/cjs/defer.d.cts +1 -1
  5. package/dist/cjs/fileRoute.d.cts +3 -3
  6. package/dist/cjs/index.d.cts +27 -27
  7. package/dist/cjs/lazyRouteComponent.d.cts +1 -1
  8. package/dist/cjs/link.d.cts +6 -6
  9. package/dist/cjs/location.d.cts +1 -1
  10. package/dist/cjs/path.d.cts +2 -2
  11. package/dist/cjs/redirects.d.cts +4 -4
  12. package/dist/cjs/route.d.cts +7 -7
  13. package/dist/cjs/routeInfo.d.cts +2 -2
  14. package/dist/cjs/router.cjs +12 -9
  15. package/dist/cjs/router.cjs.map +1 -1
  16. package/dist/cjs/router.d.cts +21 -12
  17. package/dist/cjs/routerContext.d.cts +1 -1
  18. package/dist/cjs/scroll-restoration.d.cts +1 -1
  19. package/dist/cjs/searchParams.d.cts +1 -1
  20. package/dist/cjs/useBlocker.d.cts +1 -1
  21. package/dist/cjs/useNavigate.d.cts +5 -5
  22. package/dist/cjs/useParams.d.cts +5 -5
  23. package/dist/cjs/useRouteContext.d.cts +4 -4
  24. package/dist/cjs/useRouter.d.cts +2 -2
  25. package/dist/cjs/useRouterState.d.cts +2 -2
  26. package/dist/cjs/useSearch.d.cts +4 -4
  27. package/dist/esm/Matches.d.ts +5 -5
  28. package/dist/esm/RouterProvider.d.ts +6 -6
  29. package/dist/esm/awaited.d.ts +1 -1
  30. package/dist/esm/defer.d.ts +1 -1
  31. package/dist/esm/fileRoute.d.ts +3 -3
  32. package/dist/esm/index.d.ts +27 -27
  33. package/dist/esm/lazyRouteComponent.d.ts +1 -1
  34. package/dist/esm/link.d.ts +6 -6
  35. package/dist/esm/location.d.ts +1 -1
  36. package/dist/esm/path.d.ts +2 -2
  37. package/dist/esm/redirects.d.ts +4 -4
  38. package/dist/esm/route.d.ts +7 -7
  39. package/dist/esm/routeInfo.d.ts +2 -2
  40. package/dist/esm/router.d.ts +21 -12
  41. package/dist/esm/router.js +12 -9
  42. package/dist/esm/router.js.map +1 -1
  43. package/dist/esm/routerContext.d.ts +1 -1
  44. package/dist/esm/scroll-restoration.d.ts +1 -1
  45. package/dist/esm/searchParams.d.ts +1 -1
  46. package/dist/esm/useBlocker.d.ts +1 -1
  47. package/dist/esm/useNavigate.d.ts +5 -5
  48. package/dist/esm/useParams.d.ts +5 -5
  49. package/dist/esm/useRouteContext.d.ts +4 -4
  50. package/dist/esm/useRouter.d.ts +2 -2
  51. package/dist/esm/useRouterState.d.ts +2 -2
  52. package/dist/esm/useSearch.d.ts +4 -4
  53. package/package.json +2 -2
  54. package/src/router.ts +21 -7
@@ -1,8 +1,8 @@
1
1
  /// <reference types="react" />
2
2
  import { NoInfer } from '@tanstack/react-store';
3
- import { ParsePathParams } from './link';
4
- import { AnyRoute, ResolveFullPath, ResolveFullSearchSchema, MergeFromFromParent, RouteContext, AnyContext, RouteOptions, UpdatableRouteOptions, Route, RootRouteId, TrimPathLeft, RouteConstraints, ResolveFullSearchSchemaInput, SearchSchemaInput, RouteLoaderFn, AnySearchSchema } from './route';
5
- import { Assign, Expand, IsAny } from './utils';
3
+ import { ParsePathParams } from './link.js';
4
+ import { AnyRoute, ResolveFullPath, ResolveFullSearchSchema, MergeFromFromParent, RouteContext, AnyContext, RouteOptions, UpdatableRouteOptions, Route, RootRouteId, TrimPathLeft, RouteConstraints, ResolveFullSearchSchemaInput, SearchSchemaInput, RouteLoaderFn, AnySearchSchema } from './route.js';
5
+ import { Assign, Expand, IsAny } from './utils.js';
6
6
  import { RegisteredRouter, RouteById, RouteIds } from '.';
7
7
  export interface FileRoutesByPath {
8
8
  }
@@ -1,30 +1,30 @@
1
1
  export * from '@tanstack/history';
2
2
  export { default as invariant } from 'tiny-invariant';
3
3
  export { default as warning } from 'tiny-warning';
4
- export * from './awaited';
5
- export * from './defer';
6
- export * from './CatchBoundary';
7
- export * from './fileRoute';
8
- export * from './history';
9
- export * from './lazyRouteComponent';
10
- export * from './link';
11
- export * from './location';
12
- export * from './Matches';
13
- export * from './path';
14
- export * from './qss';
15
- export * from './redirects';
16
- export * from './route';
17
- export * from './routeInfo';
18
- export * from './router';
19
- export * from './RouterProvider';
20
- export * from './scroll-restoration';
21
- export * from './searchParams';
22
- export * from './useBlocker';
23
- export * from './useNavigate';
24
- export * from './useParams';
25
- export * from './useSearch';
26
- export * from './routerContext';
27
- export * from './useRouteContext';
28
- export * from './useRouter';
29
- export * from './useRouterState';
30
- export * from './utils';
4
+ export * from './awaited.js';
5
+ export * from './defer.js';
6
+ export * from './CatchBoundary.js';
7
+ export * from './fileRoute.js';
8
+ export * from './history.js';
9
+ export * from './lazyRouteComponent.js';
10
+ export * from './link.js';
11
+ export * from './location.js';
12
+ export * from './Matches.js';
13
+ export * from './path.js';
14
+ export * from './qss.js';
15
+ export * from './redirects.js';
16
+ export * from './route.js';
17
+ export * from './routeInfo.js';
18
+ export * from './router.js';
19
+ export * from './RouterProvider.js';
20
+ export * from './scroll-restoration.js';
21
+ export * from './searchParams.js';
22
+ export * from './useBlocker.js';
23
+ export * from './useNavigate.js';
24
+ export * from './useParams.js';
25
+ export * from './useSearch.js';
26
+ export * from './routerContext.js';
27
+ export * from './useRouteContext.js';
28
+ export * from './useRouter.js';
29
+ export * from './useRouterState.js';
30
+ export * from './utils.js';
@@ -1,2 +1,2 @@
1
- import { AsyncRouteComponent } from './route';
1
+ import { AsyncRouteComponent } from './route.js';
2
2
  export declare function lazyRouteComponent<T extends Record<string, any>, TKey extends keyof T = 'default'>(importer: () => Promise<T>, exportName?: TKey): T[TKey] extends (props: infer TProps) => any ? AsyncRouteComponent<TProps> : never;
@@ -1,10 +1,10 @@
1
1
  import * as React from 'react';
2
- import { Trim } from './fileRoute';
3
- import { AnyRoute, ReactNode, RootSearchSchema } from './route';
4
- import { RouteByPath, RoutePaths } from './routeInfo';
5
- import { RegisteredRouter } from './router';
6
- import { LinkProps, UseLinkPropsOptions } from './useNavigate';
7
- import { Expand, NoInfer, NonNullableUpdater, PickRequired, StringLiteral, Updater, WithoutEmpty } from './utils';
2
+ import { Trim } from './fileRoute.js';
3
+ import { AnyRoute, ReactNode, RootSearchSchema } from './route.js';
4
+ import { RouteByPath, RoutePaths } from './routeInfo.js';
5
+ import { RegisteredRouter } from './router.js';
6
+ import { LinkProps, UseLinkPropsOptions } from './useNavigate.js';
7
+ import { Expand, NoInfer, NonNullableUpdater, PickRequired, StringLiteral, Updater, WithoutEmpty } from './utils.js';
8
8
  import { HistoryState } from '@tanstack/history';
9
9
  export type CleanPath<T extends string> = T extends `${infer L}//${infer R}` ? CleanPath<`${CleanPath<L>}/${CleanPath<R>}`> : T extends `${infer L}//` ? `${CleanPath<L>}/` : T extends `//${infer L}` ? `/${CleanPath<L>}` : T;
10
10
  export type Split<S, TIncludeTrailingSlash = true> = S extends unknown ? string extends S ? string[] : S extends string ? CleanPath<S> extends '' ? [] : TIncludeTrailingSlash extends true ? CleanPath<S> extends `${infer T}/` ? [...Split<T>, '/'] : CleanPath<S> extends `/${infer U}` ? Split<U> : CleanPath<S> extends `${infer T}/${infer U}` ? [...Split<T>, ...Split<U>] : [S] : CleanPath<S> extends `${infer T}/${infer U}` ? [...Split<T>, ...Split<U>] : S extends string ? [S] : never : never : never;
@@ -1,5 +1,5 @@
1
1
  import { HistoryState } from '@tanstack/history';
2
- import { AnySearchSchema } from './route';
2
+ import { AnySearchSchema } from './route.js';
3
3
  export interface ParsedLocation<TSearchObj extends AnySearchSchema = {}> {
4
4
  href: string;
5
5
  pathname: string;
@@ -1,5 +1,5 @@
1
- import { MatchLocation } from './RouterProvider';
2
- import { AnyPathParams } from './route';
1
+ import { MatchLocation } from './RouterProvider.js';
2
+ import { AnyPathParams } from './route.js';
3
3
  export interface Segment {
4
4
  type: 'pathname' | 'param' | 'wildcard';
5
5
  value: string;
@@ -1,7 +1,7 @@
1
- import { NavigateOptions } from './link';
2
- import { AnyRoute } from './route';
3
- import { RoutePaths } from './routeInfo';
4
- import { RegisteredRouter } from './router';
1
+ import { NavigateOptions } from './link.js';
2
+ import { AnyRoute } from './route.js';
3
+ import { RoutePaths } from './routeInfo.js';
4
+ import { RegisteredRouter } from './router.js';
5
5
  export type AnyRedirect = Redirect<any, any, any, any, any>;
6
6
  export type Redirect<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TFrom extends RoutePaths<TRouteTree> = '/', TTo extends string = '', TMaskFrom extends RoutePaths<TRouteTree> = TFrom, TMaskTo extends string = ''> = {
7
7
  code?: number;
@@ -1,11 +1,11 @@
1
1
  import * as React from 'react';
2
- import { AnyRouteMatch } from './Matches';
3
- import { NavigateOptions, ParsePathParams, ToSubOptions } from './link';
4
- import { ParsedLocation } from './location';
5
- import { RouteById, RouteIds, RoutePaths } from './routeInfo';
6
- import { AnyRouter, RegisteredRouter } from './router';
7
- import { Assign, Expand, IsAny, NoInfer, PickRequired, UnionToIntersection } from './utils';
8
- import { BuildLocationFn, NavigateFn } from './RouterProvider';
2
+ import { AnyRouteMatch } from './Matches.js';
3
+ import { NavigateOptions, ParsePathParams, ToSubOptions } from './link.js';
4
+ import { ParsedLocation } from './location.js';
5
+ import { RouteById, RouteIds, RoutePaths } from './routeInfo.js';
6
+ import { AnyRouter, RegisteredRouter } from './router.js';
7
+ import { Assign, Expand, IsAny, NoInfer, PickRequired, UnionToIntersection } from './utils.js';
8
+ import { BuildLocationFn, NavigateFn } from './RouterProvider.js';
9
9
  import { LazyRoute } from '.';
10
10
  export declare const rootRouteId: "__root__";
11
11
  export type RootRouteId = typeof rootRouteId;
@@ -1,5 +1,5 @@
1
- import { AnyRoute, Route } from './route';
2
- import { Expand, UnionToIntersection, UnionToTuple } from './utils';
1
+ import { AnyRoute, Route } from './route.js';
2
+ import { Expand, UnionToIntersection, UnionToTuple } from './utils.js';
3
3
  export type ParseRoute<TRouteTree extends AnyRoute> = TRouteTree | ParseRouteChildren<TRouteTree>;
4
4
  export type ParseRouteChildren<TRouteTree extends AnyRoute> = TRouteTree extends Route<any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, infer TChildren, any> ? unknown extends TChildren ? never : TChildren extends AnyRoute[] ? {
5
5
  [TId in TChildren[number]['id'] as string]: ParseRoute<TChildren[number]>;
@@ -1,19 +1,21 @@
1
1
  /// <reference types="react" />
2
2
  import { HistoryState, RouterHistory } from '@tanstack/history';
3
3
  import { Store } from '@tanstack/react-store';
4
- import { AnySearchSchema, AnyRoute, AnyContext, RouteMask } from './route';
5
- import { FullSearchSchema, RouteById, RoutePaths, RoutesById, RoutesByPath } from './routeInfo';
6
- import { PickAsRequired, Updater, NonNullableUpdater, Timeout } from './utils';
7
- import { RouteComponent } from './route';
8
- import { AnyRouteMatch, MatchRouteOptions, RouteMatch } from './Matches';
9
- import { ParsedLocation } from './location';
10
- import { SearchSerializer, SearchParser } from './searchParams';
11
- import { BuildLocationFn, CommitLocationOptions, InjectedHtmlEntry, NavigateFn } from './RouterProvider';
12
- import { ResolveRelativePath, ToOptions } from './link';
4
+ import { AnySearchSchema, AnyRoute, AnyContext, RouteMask } from './route.js';
5
+ import { FullSearchSchema, RouteById, RoutePaths, RoutesById, RoutesByPath } from './routeInfo.js';
6
+ import { PickAsRequired, Updater, NonNullableUpdater, Timeout } from './utils.js';
7
+ import { RouteComponent } from './route.js';
8
+ import { AnyRouteMatch, MatchRouteOptions, RouteMatch } from './Matches.js';
9
+ import { ParsedLocation } from './location.js';
10
+ import { SearchSerializer, SearchParser } from './searchParams.js';
11
+ import { BuildLocationFn, CommitLocationOptions, InjectedHtmlEntry, NavigateFn } from './RouterProvider.js';
12
+ import { ResolveRelativePath, ToOptions } from './link.js';
13
13
  import { NoInfer } from '@tanstack/react-store';
14
14
  declare global {
15
15
  interface Window {
16
- __TSR_DEHYDRATED__?: HydrationCtx;
16
+ __TSR_DEHYDRATED__?: {
17
+ data: string;
18
+ };
17
19
  __TSR_ROUTER_CONTEXT__?: React.Context<Router<any>>;
18
20
  }
19
21
  }
@@ -62,8 +64,13 @@ export interface RouterOptions<TRouteTree extends AnyRoute, TDehydrated extends
62
64
  children: any;
63
65
  }) => JSX.Element;
64
66
  notFoundRoute?: AnyRoute;
67
+ transformer?: RouterTransformer;
65
68
  errorSerializer?: RouterErrorSerializer<TSerializedError>;
66
69
  }
70
+ export interface RouterTransformer {
71
+ stringify: (obj: unknown) => string;
72
+ parse: (str: string) => unknown;
73
+ }
67
74
  export interface RouterErrorSerializer<TSerializedError> {
68
75
  serialize: (err: unknown) => TSerializedError;
69
76
  deserialize: (err: TSerializedError) => unknown;
@@ -143,7 +150,9 @@ export declare class Router<TRouteTree extends AnyRoute = AnyRoute, TDehydrated
143
150
  injectedHtml: InjectedHtmlEntry[];
144
151
  dehydratedData?: TDehydrated;
145
152
  __store: Store<RouterState<TRouteTree>>;
146
- options: PickAsRequired<RouterOptions<TRouteTree, TDehydrated, TSerializedError>, 'stringifySearch' | 'parseSearch' | 'context'>;
153
+ options: PickAsRequired<Omit<RouterOptions<TRouteTree, TDehydrated, TSerializedError>, 'transformer'> & {
154
+ transformer: RouterTransformer;
155
+ }, 'stringifySearch' | 'parseSearch' | 'context'>;
147
156
  history: RouterHistory;
148
157
  latestLocation: ParsedLocation;
149
158
  basepath: string;
@@ -186,7 +195,7 @@ export declare class Router<TRouteTree extends AnyRoute = AnyRoute, TDehydrated
186
195
  dehydrateData: <T>(key: any, getData: T | (() => T | Promise<T>)) => () => T | undefined;
187
196
  hydrateData: <T extends unknown = unknown>(key: any) => T | undefined;
188
197
  dehydrate: () => DehydratedRouter;
189
- hydrate: (__do_not_use_server_ctx?: HydrationCtx) => Promise<void>;
198
+ hydrate: (__do_not_use_server_ctx?: string) => Promise<void>;
190
199
  }
191
200
  export declare function lazyFn<T extends Record<string, (...args: any[]) => any>, TKey extends keyof T = 'default'>(fn: () => Promise<T>, key?: TKey): (...args: Parameters<T[TKey]>) => Promise<Awaited<ReturnType<T[TKey]>>>;
192
201
  export declare class SearchParamError extends Error {
@@ -964,7 +964,7 @@ class Router {
964
964
  const data = typeof getData === "function" ? await getData() : getData;
965
965
  return `<script id='${id}' suppressHydrationWarning>window["__TSR_DEHYDRATED__${escapeJSON(
966
966
  strKey
967
- )}"] = ${JSON.stringify(data)}
967
+ )}"] = ${JSON.stringify(this.options.transformer.stringify(data))}
968
968
  ;(() => {
969
969
  var el = document.getElementById('${id}')
970
970
  el.parentElement.removeChild(el)
@@ -978,7 +978,9 @@ class Router {
978
978
  this.hydrateData = (key) => {
979
979
  if (typeof document !== "undefined") {
980
980
  const strKey = typeof key === "string" ? key : JSON.stringify(key);
981
- return window[`__TSR_DEHYDRATED__${strKey}`];
981
+ return this.options.transformer.parse(
982
+ window[`__TSR_DEHYDRATED__${strKey}`]
983
+ );
982
984
  }
983
985
  return void 0;
984
986
  };
@@ -1000,24 +1002,24 @@ class Router {
1000
1002
  };
1001
1003
  };
1002
1004
  this.hydrate = async (__do_not_use_server_ctx) => {
1003
- var _a, _b;
1005
+ var _a, _b, _c;
1004
1006
  let _ctx = __do_not_use_server_ctx;
1005
1007
  if (typeof document !== "undefined") {
1006
- _ctx = window.__TSR_DEHYDRATED__;
1008
+ _ctx = (_a = window.__TSR_DEHYDRATED__) == null ? void 0 : _a.data;
1007
1009
  }
1008
1010
  invariant(
1009
1011
  _ctx,
1010
1012
  "Expected to find a __TSR_DEHYDRATED__ property on window... but we did not. Did you forget to render <DehydrateRouter /> in your app?"
1011
1013
  );
1012
- const ctx = _ctx;
1014
+ const ctx = this.options.transformer.parse(_ctx);
1013
1015
  this.dehydratedData = ctx.payload;
1014
- (_b = (_a = this.options).hydrate) == null ? void 0 : _b.call(_a, ctx.payload);
1016
+ (_c = (_b = this.options).hydrate) == null ? void 0 : _c.call(_b, ctx.payload);
1015
1017
  const dehydratedState = ctx.router.state;
1016
1018
  let matches = this.matchRoutes(
1017
1019
  this.state.location.pathname,
1018
1020
  this.state.location.search
1019
1021
  ).map((match) => {
1020
- var _a2, _b2, _c, _d, _e, _f;
1022
+ var _a2, _b2, _c2, _d, _e, _f;
1021
1023
  const dehydratedMatch = dehydratedState.dehydratedMatches.find(
1022
1024
  (d) => d.id === match.id
1023
1025
  );
@@ -1033,7 +1035,7 @@ class Router {
1033
1035
  meta: (_b2 = (_a2 = route.options).meta) == null ? void 0 : _b2.call(_a2, {
1034
1036
  loaderData: dehydratedMatch.loaderData
1035
1037
  }),
1036
- links: (_d = (_c = route.options).links) == null ? void 0 : _d.call(_c),
1038
+ links: (_d = (_c2 = route.options).links) == null ? void 0 : _d.call(_c2),
1037
1039
  scripts: (_f = (_e = route.options).scripts) == null ? void 0 : _f.call(_e)
1038
1040
  };
1039
1041
  }
@@ -1054,7 +1056,8 @@ class Router {
1054
1056
  context: void 0,
1055
1057
  ...options,
1056
1058
  stringifySearch: (options == null ? void 0 : options.stringifySearch) ?? defaultStringifySearch,
1057
- parseSearch: (options == null ? void 0 : options.parseSearch) ?? defaultParseSearch
1059
+ parseSearch: (options == null ? void 0 : options.parseSearch) ?? defaultParseSearch,
1060
+ transformer: (options == null ? void 0 : options.transformer) ?? JSON
1058
1061
  });
1059
1062
  }
1060
1063
  get state() {