@tanstack/react-router 1.6.1 → 1.7.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.
@@ -64,3 +64,8 @@ export declare function useLoaderDeps<TRouteTree extends AnyRoute = RegisteredRo
64
64
  export declare function useLoaderData<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TFrom extends RouteIds<TRouteTree> = RouteIds<TRouteTree>, TRouteMatch extends RouteMatch<TRouteTree, TFrom> = RouteMatch<TRouteTree, TFrom>, TSelected = Required<TRouteMatch>['loaderData']>(opts: StrictOrFrom<TFrom> & {
65
65
  select?: (match: TRouteMatch) => TSelected;
66
66
  }): TSelected;
67
+ export declare function isServerSideError(error: unknown): error is {
68
+ __isServerError: true;
69
+ data: Record<string, any>;
70
+ };
71
+ export declare function defaultDeserializeError(serializedData: Record<string, any>): any;
@@ -1,3 +1,4 @@
1
+ import { defaultSerializeError } from './router';
1
2
  export type DeferredPromiseState<T> = {
2
3
  uid: string;
3
4
  } & ({
@@ -15,5 +16,7 @@ export type DeferredPromiseState<T> = {
15
16
  export type DeferredPromise<T> = Promise<T> & {
16
17
  __deferredState: DeferredPromiseState<T>;
17
18
  };
18
- export declare function defer<T>(_promise: Promise<T>): DeferredPromise<T>;
19
+ export declare function defer<T>(_promise: Promise<T>, options?: {
20
+ serializeError?: typeof defaultSerializeError;
21
+ }): DeferredPromise<T>;
19
22
  export declare function isDehydratedDeferred(obj: any): boolean;
@@ -32,7 +32,7 @@ export type RouterContextOptions<TRouteTree extends AnyRoute> = AnyContext exten
32
32
  } : {
33
33
  context: TRouteTree['types']['routerContext'];
34
34
  };
35
- export interface RouterOptions<TRouteTree extends AnyRoute, TDehydrated extends Record<string, any> = Record<string, any>> {
35
+ export interface RouterOptions<TRouteTree extends AnyRoute, TDehydrated extends Record<string, any> = Record<string, any>, TSerializedError extends Record<string, any> = Record<string, any>> {
36
36
  history?: RouterHistory;
37
37
  stringifySearch?: SearchSerializer;
38
38
  parseSearch?: SearchParser;
@@ -62,6 +62,11 @@ export interface RouterOptions<TRouteTree extends AnyRoute, TDehydrated extends
62
62
  children: any;
63
63
  }) => JSX.Element;
64
64
  notFoundRoute?: AnyRoute;
65
+ errorSerializer?: RouterErrorSerializer<TSerializedError>;
66
+ }
67
+ export interface RouterErrorSerializer<TSerializedError> {
68
+ serialize: (err: unknown) => TSerializedError;
69
+ deserialize: (err: TSerializedError) => unknown;
65
70
  }
66
71
  export interface RouterState<TRouteTree extends AnyRoute = AnyRoute> {
67
72
  status: 'pending' | 'idle';
@@ -98,7 +103,7 @@ export type DehydratedRouteMatch = Pick<RouteMatch, 'id' | 'status' | 'updatedAt
98
103
  export interface DehydratedRouter {
99
104
  state: DehydratedRouterState;
100
105
  }
101
- export type RouterConstructorOptions<TRouteTree extends AnyRoute, TDehydrated extends Record<string, any>> = Omit<RouterOptions<TRouteTree, TDehydrated>, 'context'> & RouterContextOptions<TRouteTree>;
106
+ export type RouterConstructorOptions<TRouteTree extends AnyRoute, TDehydrated extends Record<string, any>, TSerializedError extends Record<string, any>> = Omit<RouterOptions<TRouteTree, TDehydrated, TSerializedError>, 'context'> & RouterContextOptions<TRouteTree>;
102
107
  export declare const componentTypes: readonly ["component", "errorComponent", "pendingComponent"];
103
108
  export type RouterEvents = {
104
109
  onBeforeLoad: {
@@ -125,7 +130,7 @@ export type RouterListener<TRouterEvent extends RouterEvent> = {
125
130
  eventType: TRouterEvent['type'];
126
131
  fn: ListenerFn<TRouterEvent>;
127
132
  };
128
- export declare class Router<TRouteTree extends AnyRoute = AnyRoute, TDehydrated extends Record<string, any> = Record<string, any>> {
133
+ export declare class Router<TRouteTree extends AnyRoute = AnyRoute, TDehydrated extends Record<string, any> = Record<string, any>, TSerializedError extends Record<string, any> = Record<string, any>> {
129
134
  tempLocationKey: string | undefined;
130
135
  resetNextScroll: boolean;
131
136
  navigateTimeout: Timeout | null;
@@ -134,7 +139,7 @@ export declare class Router<TRouteTree extends AnyRoute = AnyRoute, TDehydrated
134
139
  injectedHtml: InjectedHtmlEntry[];
135
140
  dehydratedData?: TDehydrated;
136
141
  __store: Store<RouterState<TRouteTree>>;
137
- options: PickAsRequired<RouterOptions<TRouteTree, TDehydrated>, 'stringifySearch' | 'parseSearch' | 'context'>;
142
+ options: PickAsRequired<RouterOptions<TRouteTree, TDehydrated, TSerializedError>, 'stringifySearch' | 'parseSearch' | 'context'>;
138
143
  history: RouterHistory;
139
144
  latestLocation: ParsedLocation;
140
145
  basepath: string;
@@ -142,9 +147,9 @@ export declare class Router<TRouteTree extends AnyRoute = AnyRoute, TDehydrated
142
147
  routesById: RoutesById<TRouteTree>;
143
148
  routesByPath: RoutesByPath<TRouteTree>;
144
149
  flatRoutes: AnyRoute[];
145
- constructor(options: RouterConstructorOptions<TRouteTree, TDehydrated>);
150
+ constructor(options: RouterConstructorOptions<TRouteTree, TDehydrated, TSerializedError>);
146
151
  startReactTransition: (fn: () => void) => void;
147
- update: (newOptions: RouterConstructorOptions<TRouteTree, TDehydrated>) => void;
152
+ update: (newOptions: RouterConstructorOptions<TRouteTree, TDehydrated, TSerializedError>) => void;
148
153
  get state(): RouterState<TRouteTree>;
149
154
  buildRouteTree: () => void;
150
155
  subscribe: <TType extends keyof RouterEvents>(eventType: TType, fn: ListenerFn<RouterEvents[TType]>) => () => void;
@@ -185,3 +190,12 @@ export declare class SearchParamError extends Error {
185
190
  export declare class PathParamError extends Error {
186
191
  }
187
192
  export declare function getInitialRouterState(location: ParsedLocation): RouterState<any>;
193
+ export declare function defaultSerializeError(err: unknown): {
194
+ name: string;
195
+ message: string;
196
+ data?: undefined;
197
+ } | {
198
+ data: unknown;
199
+ name?: undefined;
200
+ message?: undefined;
201
+ };
@@ -1,3 +1,3 @@
1
1
  import * as React from 'react';
2
2
  import { Router } from './router';
3
- export declare let routerContext: React.Context<Router<any, Record<string, any>>>;
3
+ export declare let routerContext: React.Context<Router<any, Record<string, any>, Record<string, any>>>;