@tanstack/react-router 1.97.0 → 1.97.3
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.
- package/dist/cjs/defer.cjs.map +1 -1
- package/dist/cjs/defer.d.cts +13 -13
- package/dist/cjs/index.d.cts +1 -1
- package/dist/cjs/router.cjs.map +1 -1
- package/dist/cjs/router.d.cts +33 -25
- package/dist/esm/defer.d.ts +13 -13
- package/dist/esm/defer.js.map +1 -1
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/router.d.ts +33 -25
- package/dist/esm/router.js.map +1 -1
- package/package.json +2 -2
- package/src/defer.ts +18 -18
- package/src/index.tsx +6 -3
- package/src/router.ts +40 -28
package/dist/cjs/router.d.cts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Store, NoInfer } from '@tanstack/react-store';
|
|
2
|
-
import { DeferredPromiseState } from './defer.cjs';
|
|
3
2
|
import { HistoryLocation, HistoryState, ParsedHistoryState, RouterHistory } from '@tanstack/history';
|
|
4
3
|
import { Manifest } from './manifest.cjs';
|
|
5
4
|
import { AnyContext, AnyRoute, AnyRouteWithContext, ErrorRouteComponent, NotFoundRouteComponent, RootRoute, RouteComponent, RouteMask } from './route.cjs';
|
|
@@ -15,24 +14,30 @@ import { NavigateOptions, ResolveRelativePath, ToOptions } from './link.cjs';
|
|
|
15
14
|
import { RouterTransformer } from './transformer.cjs';
|
|
16
15
|
import { AnySchema } from './validators.cjs';
|
|
17
16
|
import type * as React from 'react';
|
|
17
|
+
export interface TSRGlobalMatch {
|
|
18
|
+
index: number;
|
|
19
|
+
__beforeLoadContext?: string;
|
|
20
|
+
loaderData?: string;
|
|
21
|
+
extracted: Record<string, ClientExtractedEntry>;
|
|
22
|
+
}
|
|
23
|
+
export interface TSRGlobal {
|
|
24
|
+
matches: Array<TSRGlobalMatch>;
|
|
25
|
+
streamedValues: Record<string, {
|
|
26
|
+
value: any;
|
|
27
|
+
parsed: any;
|
|
28
|
+
}>;
|
|
29
|
+
cleanScripts: () => void;
|
|
30
|
+
dehydrated?: any;
|
|
31
|
+
}
|
|
18
32
|
declare global {
|
|
19
33
|
interface Window {
|
|
20
|
-
__TSR__?:
|
|
21
|
-
matches: Array<{
|
|
22
|
-
__beforeLoadContext?: string;
|
|
23
|
-
loaderData?: string;
|
|
24
|
-
extracted?: Array<ExtractedEntry>;
|
|
25
|
-
}>;
|
|
26
|
-
streamedValues: Record<string, {
|
|
27
|
-
value: any;
|
|
28
|
-
parsed: any;
|
|
29
|
-
}>;
|
|
30
|
-
cleanScripts: () => void;
|
|
31
|
-
dehydrated?: any;
|
|
32
|
-
};
|
|
34
|
+
__TSR__?: RegisteredTSRGlobal;
|
|
33
35
|
__TSR_ROUTER_CONTEXT__?: React.Context<Router<any, any, any>>;
|
|
34
36
|
}
|
|
35
37
|
}
|
|
38
|
+
type RegisteredTSRGlobal = Register extends {
|
|
39
|
+
__TSR__: infer TTSR extends TSRGlobal;
|
|
40
|
+
} ? TTSR : TSRGlobal;
|
|
36
41
|
export interface Register {
|
|
37
42
|
}
|
|
38
43
|
export type AnyRouter = Router<any, any, any, any, any, any>;
|
|
@@ -45,22 +50,25 @@ export type HydrationCtx = {
|
|
|
45
50
|
payload: Record<string, any>;
|
|
46
51
|
};
|
|
47
52
|
export type InferRouterContext<TRouteTree extends AnyRoute> = TRouteTree extends RootRoute<any, infer TRouterContext extends AnyContext, any, any, any, any, any, any> ? TRouterContext : AnyContext;
|
|
48
|
-
export interface
|
|
49
|
-
dataType: '__beforeLoadContext' | 'loaderData';
|
|
53
|
+
export interface ClientExtractedBaseEntry {
|
|
50
54
|
type: string;
|
|
51
55
|
path: Array<string>;
|
|
52
|
-
id: number;
|
|
53
|
-
matchIndex: number;
|
|
54
|
-
}
|
|
55
|
-
export interface ExtractedStream extends ExtractedBaseEntry {
|
|
56
|
-
type: 'stream';
|
|
57
|
-
streamState: StreamState;
|
|
58
56
|
}
|
|
59
|
-
export
|
|
57
|
+
export type ControllablePromise<T = any> = Promise<T> & {
|
|
58
|
+
resolve: (value: T) => void;
|
|
59
|
+
reject: (value?: any) => void;
|
|
60
|
+
};
|
|
61
|
+
export interface ClientExtractedPromise extends ClientExtractedBaseEntry {
|
|
60
62
|
type: 'promise';
|
|
61
|
-
|
|
63
|
+
value?: ControllablePromise<any>;
|
|
64
|
+
}
|
|
65
|
+
export interface ClientExtractedStream extends ClientExtractedBaseEntry {
|
|
66
|
+
type: 'stream';
|
|
67
|
+
value?: ReadableStream & {
|
|
68
|
+
controller?: ReadableStreamDefaultController;
|
|
69
|
+
};
|
|
62
70
|
}
|
|
63
|
-
export type
|
|
71
|
+
export type ClientExtractedEntry = ClientExtractedStream | ClientExtractedPromise;
|
|
64
72
|
export type StreamState = {
|
|
65
73
|
promises: Array<ControlledPromise<string | null>>;
|
|
66
74
|
};
|
package/dist/esm/defer.d.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import { defaultSerializeError } from './router.js';
|
|
2
2
|
export declare const TSR_DEFERRED_PROMISE: unique symbol;
|
|
3
3
|
export type DeferredPromiseState<T> = {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
4
|
+
status: 'pending';
|
|
5
|
+
data?: T;
|
|
6
|
+
error?: unknown;
|
|
7
|
+
} | {
|
|
8
|
+
status: 'success';
|
|
9
|
+
data: T;
|
|
10
|
+
} | {
|
|
11
|
+
status: 'error';
|
|
12
|
+
data?: T;
|
|
13
|
+
error: unknown;
|
|
14
|
+
};
|
|
15
|
+
export type DeferredPromise<T> = Promise<T> & {
|
|
16
|
+
[TSR_DEFERRED_PROMISE]: DeferredPromiseState<T>;
|
|
16
17
|
};
|
|
17
|
-
export type DeferredPromise<T> = Promise<T> & DeferredPromiseState<T>;
|
|
18
18
|
export declare function defer<T>(_promise: Promise<T>, options?: {
|
|
19
19
|
serializeError?: typeof defaultSerializeError;
|
|
20
20
|
}): DeferredPromise<T>;
|
package/dist/esm/defer.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defer.js","sources":["../../src/defer.ts"],"sourcesContent":["import { defaultSerializeError } from './router'\n\nexport const TSR_DEFERRED_PROMISE = Symbol.for('TSR_DEFERRED_PROMISE')\n\nexport type DeferredPromiseState<T>
|
|
1
|
+
{"version":3,"file":"defer.js","sources":["../../src/defer.ts"],"sourcesContent":["import { defaultSerializeError } from './router'\n\nexport const TSR_DEFERRED_PROMISE = Symbol.for('TSR_DEFERRED_PROMISE')\n\nexport type DeferredPromiseState<T> =\n | {\n status: 'pending'\n data?: T\n error?: unknown\n }\n | {\n status: 'success'\n data: T\n }\n | {\n status: 'error'\n data?: T\n error: unknown\n }\n\nexport type DeferredPromise<T> = Promise<T> & {\n [TSR_DEFERRED_PROMISE]: DeferredPromiseState<T>\n}\n\nexport function defer<T>(\n _promise: Promise<T>,\n options?: {\n serializeError?: typeof defaultSerializeError\n },\n) {\n const promise = _promise as DeferredPromise<T>\n // this is already deferred promise\n if ((promise as any)[TSR_DEFERRED_PROMISE]) {\n return promise\n }\n promise[TSR_DEFERRED_PROMISE] = { status: 'pending' }\n\n promise\n .then((data) => {\n promise[TSR_DEFERRED_PROMISE].status = 'success'\n promise[TSR_DEFERRED_PROMISE].data = data\n })\n .catch((error) => {\n promise[TSR_DEFERRED_PROMISE].status = 'error'\n ;(promise[TSR_DEFERRED_PROMISE] as any).error = {\n data: (options?.serializeError ?? defaultSerializeError)(error),\n __isServerError: true,\n }\n })\n\n return promise\n}\n"],"names":[],"mappings":";AAEa,MAAA,uBAAuB,OAAO,IAAI,sBAAsB;AAsBrD,SAAA,MACd,UACA,SAGA;AACA,QAAM,UAAU;AAEX,MAAA,QAAgB,oBAAoB,GAAG;AACnC,WAAA;AAAA,EAAA;AAET,UAAQ,oBAAoB,IAAI,EAAE,QAAQ,UAAU;AAGjD,UAAA,KAAK,CAAC,SAAS;AACN,YAAA,oBAAoB,EAAE,SAAS;AAC/B,YAAA,oBAAoB,EAAE,OAAO;AAAA,EAAA,CACtC,EACA,MAAM,CAAC,UAAU;AACR,YAAA,oBAAoB,EAAE,SAAS;AACrC,YAAQ,oBAAoB,EAAU,QAAQ;AAAA,MAC9C,QAAO,mCAAS,mBAAkB,uBAAuB,KAAK;AAAA,MAC9D,iBAAiB;AAAA,IACnB;AAAA,EAAA,CACD;AAEI,SAAA;AACT;"}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -34,7 +34,7 @@ export { RouteApi, getRouteApi, Route, createRoute, RootRoute, rootRouteWithCont
|
|
|
34
34
|
export type { AnyPathParams, ResolveParams, SearchSchemaInput, AnyContext, RouteContext, PreloadableObj, RoutePathOptions, StaticDataRouteOption, RoutePathOptionsIntersection, RouteOptions, FileBaseRouteOptions, BaseRouteOptions, UpdatableRouteOptions, UpdatableStaticRouteOption, MetaDescriptor, RouteLinkEntry, ParseParamsFn, RouteLoaderFn, LoaderFnContext, SearchFilter, ResolveId, InferFullSearchSchema, InferFullSearchSchemaInput, ResolveFullSearchSchema, ResolveFullSearchSchemaInput, AnyRoute, RouteConstraints, AnyRootRoute, ResolveFullPath, RouteMask, ErrorRouteProps, ErrorComponentProps, NotFoundRouteProps, ReactNode, SyncRouteComponent, AsyncRouteComponent, RouteComponent, ErrorRouteComponent, NotFoundRouteComponent, TrimPath, TrimPathLeft, TrimPathRight, RootRouteOptions, AnyRouteWithContext, ParseSplatParams, SplatParams, StringifyParamsFn, ParamsOptions, FullSearchSchemaOption, RouteContextFn, RouteContextOptions, BeforeLoadFn, BeforeLoadContextOptions, ContextOptions, InferAllParams, InferAllContext, LooseReturnType, LooseAsyncReturnType, ContextReturnType, ContextAsyncReturnType, RouteContextParameter, BeforeLoadContextParameter, ResolveAllContext, ResolveLoaderData, ResolveAllParamsFromParent, ResolveRouteContext, } from './route.js';
|
|
35
35
|
export type { ParseRoute, RoutesById, RouteById, RouteIds, RoutesByPath, RouteByPath, RoutePaths, FullSearchSchema, AllParams, AllLoaderData, FullSearchSchemaInput, AllContext, } from './routeInfo.js';
|
|
36
36
|
export { componentTypes, createRouter, Router, lazyFn, SearchParamError, PathParamError, getInitialRouterState, defaultSerializeError, } from './router.js';
|
|
37
|
-
export type { Register, AnyRouter, RegisteredRouter, HydrationCtx, RouterContextOptions, TrailingSlashOption, RouterOptions, RouterErrorSerializer, RouterState, ListenerFn, BuildNextOptions, DehydratedRouterState, DehydratedRouteMatch, DehydratedRouter, RouterConstructorOptions, RouterEvents, RouterEvent, RouterListener, AnyRouterWithContext,
|
|
37
|
+
export type { Register, AnyRouter, RegisteredRouter, HydrationCtx, RouterContextOptions, TrailingSlashOption, RouterOptions, RouterErrorSerializer, RouterState, ListenerFn, BuildNextOptions, DehydratedRouterState, DehydratedRouteMatch, DehydratedRouter, RouterConstructorOptions, RouterEvents, RouterEvent, RouterListener, AnyRouterWithContext, ClientExtractedBaseEntry, ClientExtractedEntry, ClientExtractedPromise, ControllablePromise, StreamState, TSRGlobal, TSRGlobalMatch, } from './router.js';
|
|
38
38
|
export { RouterProvider, RouterContextProvider } from './RouterProvider.js';
|
|
39
39
|
export type { RouterProps, CommitLocationOptions, MatchLocation, NavigateFn, BuildLocationFn, InjectedHtmlEntry, } from './RouterProvider.js';
|
|
40
40
|
export { useScrollRestoration, useElementScrollRestoration, ScrollRestoration, } from './scroll-restoration.js';
|
package/dist/esm/router.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Store, NoInfer } from '@tanstack/react-store';
|
|
2
|
-
import { DeferredPromiseState } from './defer.js';
|
|
3
2
|
import { HistoryLocation, HistoryState, ParsedHistoryState, RouterHistory } from '@tanstack/history';
|
|
4
3
|
import { Manifest } from './manifest.js';
|
|
5
4
|
import { AnyContext, AnyRoute, AnyRouteWithContext, ErrorRouteComponent, NotFoundRouteComponent, RootRoute, RouteComponent, RouteMask } from './route.js';
|
|
@@ -15,24 +14,30 @@ import { NavigateOptions, ResolveRelativePath, ToOptions } from './link.js';
|
|
|
15
14
|
import { RouterTransformer } from './transformer.js';
|
|
16
15
|
import { AnySchema } from './validators.js';
|
|
17
16
|
import type * as React from 'react';
|
|
17
|
+
export interface TSRGlobalMatch {
|
|
18
|
+
index: number;
|
|
19
|
+
__beforeLoadContext?: string;
|
|
20
|
+
loaderData?: string;
|
|
21
|
+
extracted: Record<string, ClientExtractedEntry>;
|
|
22
|
+
}
|
|
23
|
+
export interface TSRGlobal {
|
|
24
|
+
matches: Array<TSRGlobalMatch>;
|
|
25
|
+
streamedValues: Record<string, {
|
|
26
|
+
value: any;
|
|
27
|
+
parsed: any;
|
|
28
|
+
}>;
|
|
29
|
+
cleanScripts: () => void;
|
|
30
|
+
dehydrated?: any;
|
|
31
|
+
}
|
|
18
32
|
declare global {
|
|
19
33
|
interface Window {
|
|
20
|
-
__TSR__?:
|
|
21
|
-
matches: Array<{
|
|
22
|
-
__beforeLoadContext?: string;
|
|
23
|
-
loaderData?: string;
|
|
24
|
-
extracted?: Array<ExtractedEntry>;
|
|
25
|
-
}>;
|
|
26
|
-
streamedValues: Record<string, {
|
|
27
|
-
value: any;
|
|
28
|
-
parsed: any;
|
|
29
|
-
}>;
|
|
30
|
-
cleanScripts: () => void;
|
|
31
|
-
dehydrated?: any;
|
|
32
|
-
};
|
|
34
|
+
__TSR__?: RegisteredTSRGlobal;
|
|
33
35
|
__TSR_ROUTER_CONTEXT__?: React.Context<Router<any, any, any>>;
|
|
34
36
|
}
|
|
35
37
|
}
|
|
38
|
+
type RegisteredTSRGlobal = Register extends {
|
|
39
|
+
__TSR__: infer TTSR extends TSRGlobal;
|
|
40
|
+
} ? TTSR : TSRGlobal;
|
|
36
41
|
export interface Register {
|
|
37
42
|
}
|
|
38
43
|
export type AnyRouter = Router<any, any, any, any, any, any>;
|
|
@@ -45,22 +50,25 @@ export type HydrationCtx = {
|
|
|
45
50
|
payload: Record<string, any>;
|
|
46
51
|
};
|
|
47
52
|
export type InferRouterContext<TRouteTree extends AnyRoute> = TRouteTree extends RootRoute<any, infer TRouterContext extends AnyContext, any, any, any, any, any, any> ? TRouterContext : AnyContext;
|
|
48
|
-
export interface
|
|
49
|
-
dataType: '__beforeLoadContext' | 'loaderData';
|
|
53
|
+
export interface ClientExtractedBaseEntry {
|
|
50
54
|
type: string;
|
|
51
55
|
path: Array<string>;
|
|
52
|
-
id: number;
|
|
53
|
-
matchIndex: number;
|
|
54
|
-
}
|
|
55
|
-
export interface ExtractedStream extends ExtractedBaseEntry {
|
|
56
|
-
type: 'stream';
|
|
57
|
-
streamState: StreamState;
|
|
58
56
|
}
|
|
59
|
-
export
|
|
57
|
+
export type ControllablePromise<T = any> = Promise<T> & {
|
|
58
|
+
resolve: (value: T) => void;
|
|
59
|
+
reject: (value?: any) => void;
|
|
60
|
+
};
|
|
61
|
+
export interface ClientExtractedPromise extends ClientExtractedBaseEntry {
|
|
60
62
|
type: 'promise';
|
|
61
|
-
|
|
63
|
+
value?: ControllablePromise<any>;
|
|
64
|
+
}
|
|
65
|
+
export interface ClientExtractedStream extends ClientExtractedBaseEntry {
|
|
66
|
+
type: 'stream';
|
|
67
|
+
value?: ReadableStream & {
|
|
68
|
+
controller?: ReadableStreamDefaultController;
|
|
69
|
+
};
|
|
62
70
|
}
|
|
63
|
-
export type
|
|
71
|
+
export type ClientExtractedEntry = ClientExtractedStream | ClientExtractedPromise;
|
|
64
72
|
export type StreamState = {
|
|
65
73
|
promises: Array<ControlledPromise<string | null>>;
|
|
66
74
|
};
|