@tanstack/router-core 0.0.1-beta.166 → 0.0.1-beta.167
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/build/cjs/defer.js +39 -0
- package/build/cjs/defer.js.map +1 -0
- package/build/cjs/index.js +3 -0
- package/build/cjs/index.js.map +1 -1
- package/build/cjs/route.js +9 -0
- package/build/cjs/route.js.map +1 -1
- package/build/cjs/router.js +28 -15
- package/build/cjs/router.js.map +1 -1
- package/build/esm/index.js +60 -16
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +150 -125
- package/build/types/index.d.ts +54 -40
- package/build/umd/index.development.js +61 -15
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +2 -2
- package/build/umd/index.production.js.map +1 -1
- package/package.json +2 -2
- package/src/defer.ts +55 -0
- package/src/index.ts +1 -0
- package/src/route.ts +114 -76
- package/src/router.ts +86 -25
package/build/types/index.d.ts
CHANGED
|
@@ -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<
|
|
192
|
-
defaultErrorComponent?: RegisteredRouteErrorComponent<
|
|
193
|
-
defaultPendingComponent?: RegisteredRouteComponent<
|
|
191
|
+
defaultComponent?: RegisteredRouteComponent<RegisteredRouteProps<unknown, AnySearchSchema, AnyPathParams, AnyContext, AnyContext>>;
|
|
192
|
+
defaultErrorComponent?: RegisteredRouteErrorComponent<RegisteredErrorRouteProps<AnySearchSchema, AnyPathParams, AnyContext, AnyContext>>;
|
|
193
|
+
defaultPendingComponent?: RegisteredRouteComponent<RegisteredRouteProps<unknown, 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
|
|
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 & {
|
|
@@ -371,12 +374,27 @@ interface RegisterRouteComponent<TProps> {
|
|
|
371
374
|
}
|
|
372
375
|
interface RegisterRouteErrorComponent<TProps> {
|
|
373
376
|
}
|
|
377
|
+
interface RegisterRouteProps<TLoader = unknown, TFullSearchSchema extends AnySearchSchema = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TRouteContext extends AnyContext = AnyContext, TAllContext extends AnyContext = AnyContext> {
|
|
378
|
+
}
|
|
379
|
+
interface RegisterErrorRouteProps<TFullSearchSchema extends AnySearchSchema = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TRouteContext extends AnyContext = AnyContext, TAllContext extends AnyContext = AnyContext> {
|
|
380
|
+
}
|
|
381
|
+
interface RegisterPendingRouteProps<TFullSearchSchema extends AnySearchSchema = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TRouteContext extends AnyContext = AnyContext, TAllContext extends AnyContext = AnyContext> {
|
|
382
|
+
}
|
|
374
383
|
type RegisteredRouteComponent<TProps> = RegisterRouteComponent<TProps> extends {
|
|
375
384
|
RouteComponent: infer T;
|
|
376
385
|
} ? T : (props: TProps) => unknown;
|
|
377
386
|
type RegisteredRouteErrorComponent<TProps> = RegisterRouteErrorComponent<TProps> extends {
|
|
378
387
|
RouteErrorComponent: infer T;
|
|
379
388
|
} ? T : (props: TProps) => unknown;
|
|
389
|
+
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 {
|
|
390
|
+
RouteProps: infer T;
|
|
391
|
+
} ? T : (props: {}) => unknown;
|
|
392
|
+
type RegisteredErrorRouteProps<TFullSearchSchema extends AnySearchSchema = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TRouteContext extends AnyContext = AnyContext, TAllContext extends AnyContext = AnyContext> = RegisterRouteProps<TFullSearchSchema, TAllParams, TRouteContext, TAllContext> extends {
|
|
393
|
+
ErrorRouteProps: infer T;
|
|
394
|
+
} ? T : (props: {}) => unknown;
|
|
395
|
+
type RegisteredPendingRouteProps<TFullSearchSchema extends AnySearchSchema = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TRouteContext extends AnyContext = AnyContext, TAllContext extends AnyContext = AnyContext> = RegisterRouteProps<TFullSearchSchema, TAllParams, TRouteContext, TAllContext> extends {
|
|
396
|
+
PendingRouteProps: infer T;
|
|
397
|
+
} ? T : (props: {}) => unknown;
|
|
380
398
|
type PreloadableObj = {
|
|
381
399
|
preload?: () => Promise<void>;
|
|
382
400
|
};
|
|
@@ -391,31 +409,10 @@ type MetaOptions = keyof PickRequired<RouteMeta> extends never ? {
|
|
|
391
409
|
} : {
|
|
392
410
|
meta: RouteMeta;
|
|
393
411
|
};
|
|
394
|
-
type AnyRouteProps =
|
|
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> ?
|
|
412
|
+
type AnyRouteProps = RegisteredRouteProps<any, any, any, any, any>;
|
|
413
|
+
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
414
|
type ComponentFromRoute<TRoute> = RegisteredRouteComponent<ComponentPropsFromRoute<TRoute>>;
|
|
397
415
|
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
416
|
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
417
|
type ParamsFallback<TPath extends string, TParams> = unknown extends TParams ? Record<ParsePathParams<TPath>, string> : TParams;
|
|
421
418
|
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 +443,19 @@ type GetContextFn<TParentRoute, TAllParams, TFullSearchSchema, TParentContext, T
|
|
|
446
443
|
context: TAllParentContext;
|
|
447
444
|
parentContext: TParentContext;
|
|
448
445
|
})) => TRouteContext;
|
|
449
|
-
type UpdatableRouteOptions<TLoader, TSearchSchema extends AnySearchSchema, TFullSearchSchema extends AnySearchSchema, TAllParams extends AnyPathParams, TRouteContext extends AnyContext,
|
|
446
|
+
type UpdatableRouteOptions<TLoader, TSearchSchema extends AnySearchSchema, TFullSearchSchema extends AnySearchSchema, TAllParams extends AnyPathParams, TRouteContext extends AnyContext, TAllContext extends AnyContext> = MetaOptions & {
|
|
450
447
|
key?: null | false | GetKeyFn<TFullSearchSchema, TAllParams>;
|
|
451
448
|
caseSensitive?: boolean;
|
|
452
449
|
wrapInSuspense?: boolean;
|
|
453
|
-
component?: RegisteredRouteComponent<
|
|
454
|
-
errorComponent?: RegisteredRouteErrorComponent<
|
|
455
|
-
pendingComponent?: RegisteredRouteComponent<
|
|
450
|
+
component?: RegisteredRouteComponent<RegisteredRouteProps<TLoader, TFullSearchSchema, TAllParams, TRouteContext, TAllContext>>;
|
|
451
|
+
errorComponent?: RegisteredRouteErrorComponent<RegisteredErrorRouteProps<TFullSearchSchema, TAllParams, TRouteContext, TAllContext>>;
|
|
452
|
+
pendingComponent?: RegisteredRouteComponent<RegisteredPendingRouteProps<TFullSearchSchema, TAllParams, TRouteContext, TAllContext>>;
|
|
456
453
|
preSearchFilters?: SearchFilter<TFullSearchSchema>[];
|
|
457
454
|
postSearchFilters?: SearchFilter<TFullSearchSchema>[];
|
|
458
455
|
preloadMaxAge?: number;
|
|
459
456
|
maxAge?: number;
|
|
460
457
|
gcMaxAge?: number;
|
|
461
|
-
beforeLoad?: (opts: LoaderContext<TSearchSchema, TFullSearchSchema, TAllParams, NoInfer<TRouteContext>,
|
|
458
|
+
beforeLoad?: (opts: LoaderContext<TSearchSchema, TFullSearchSchema, TAllParams, NoInfer<TRouteContext>, TAllContext>) => Promise<void> | void;
|
|
462
459
|
onError?: (err: any) => void;
|
|
463
460
|
onLoaded?: (matchContext: {
|
|
464
461
|
params: TAllParams;
|
|
@@ -521,10 +518,7 @@ type ResolveFullSearchSchema<TParentRoute, TSearchSchema> = InferFullSearchSchem
|
|
|
521
518
|
interface AnyRoute extends Route<any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any> {
|
|
522
519
|
}
|
|
523
520
|
type MergeParamsFromParent<T, U> = IsAny<T, U, T & U>;
|
|
524
|
-
type UseLoaderResult<T> = T
|
|
525
|
-
[K in keyof T]: UseLoaderResultPromise<T[K]>;
|
|
526
|
-
} : UseLoaderResultPromise<T>;
|
|
527
|
-
type UseLoaderResultPromise<T> = T extends Promise<infer U> ? StreamedPromise<U> : T;
|
|
521
|
+
type UseLoaderResult<T> = T;
|
|
528
522
|
type StreamedPromise<T> = {
|
|
529
523
|
promise: Promise<T>;
|
|
530
524
|
status: 'resolved' | 'pending';
|
|
@@ -622,9 +616,9 @@ declare class FileRoute<TFilePath extends keyof FileRoutesByPath, TParentRoute e
|
|
|
622
616
|
key?: false | GetKeyFn<TFullSearchSchema, TAllParams> | null | undefined;
|
|
623
617
|
caseSensitive?: boolean | undefined;
|
|
624
618
|
wrapInSuspense?: boolean | undefined;
|
|
625
|
-
component?: ((props:
|
|
626
|
-
errorComponent?: ((props:
|
|
627
|
-
pendingComponent?: ((props:
|
|
619
|
+
component?: ((props: (props: {}) => unknown) => unknown) | undefined;
|
|
620
|
+
errorComponent?: ((props: (props: {}) => unknown) => unknown) | undefined;
|
|
621
|
+
pendingComponent?: ((props: (props: {}) => unknown) => unknown) | undefined;
|
|
628
622
|
preSearchFilters?: SearchFilter<TFullSearchSchema, TFullSearchSchema>[] | undefined;
|
|
629
623
|
postSearchFilters?: SearchFilter<TFullSearchSchema, TFullSearchSchema>[] | undefined;
|
|
630
624
|
preloadMaxAge?: number | undefined;
|
|
@@ -761,4 +755,24 @@ type ScrollRestorationOptions = {
|
|
|
761
755
|
declare function watchScrollPositions(router: AnyRouter, opts?: ScrollRestorationOptions): () => void;
|
|
762
756
|
declare function restoreScrollPositions(router: AnyRouter, opts?: ScrollRestorationOptions): void;
|
|
763
757
|
|
|
764
|
-
|
|
758
|
+
type DeferredPromiseState<T> = {
|
|
759
|
+
uid: string;
|
|
760
|
+
} & ({
|
|
761
|
+
status: 'pending';
|
|
762
|
+
data?: T;
|
|
763
|
+
error?: unknown;
|
|
764
|
+
} | {
|
|
765
|
+
status: 'success';
|
|
766
|
+
data: T;
|
|
767
|
+
} | {
|
|
768
|
+
status: 'error';
|
|
769
|
+
data?: T;
|
|
770
|
+
error: unknown;
|
|
771
|
+
});
|
|
772
|
+
type DeferredPromise<T> = Promise<T> & {
|
|
773
|
+
__deferredState: DeferredPromiseState<T>;
|
|
774
|
+
};
|
|
775
|
+
declare function defer<T>(_promise: Promise<T>): DeferredPromise<T>;
|
|
776
|
+
declare function isDehydratedDeferred(obj: any): boolean;
|
|
777
|
+
|
|
778
|
+
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, RegisterErrorRouteProps, RegisterPendingRouteProps, RegisterRouteComponent, RegisterRouteErrorComponent, RegisterRouteProps, RegisteredErrorRouteProps, RegisteredPendingRouteProps, RegisteredRouteComponent, RegisteredRouteErrorComponent, 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.#
|
|
920
|
+
this.#processRoutes(routeTree);
|
|
912
921
|
}
|
|
913
922
|
return this;
|
|
914
923
|
};
|
|
@@ -1144,8 +1153,8 @@
|
|
|
1144
1153
|
params: routeParams,
|
|
1145
1154
|
pathname: joinPaths([this.basepath, interpolatedPath]),
|
|
1146
1155
|
updatedAt: Date.now(),
|
|
1147
|
-
invalidAt:
|
|
1148
|
-
preloadInvalidAt:
|
|
1156
|
+
invalidAt: 9999999999999,
|
|
1157
|
+
preloadInvalidAt: 9999999999999,
|
|
1149
1158
|
routeSearch: {},
|
|
1150
1159
|
search: {},
|
|
1151
1160
|
status: hasLoaders ? 'pending' : 'success',
|
|
@@ -1559,7 +1568,9 @@
|
|
|
1559
1568
|
};
|
|
1560
1569
|
dehydrate = () => {
|
|
1561
1570
|
return {
|
|
1562
|
-
state:
|
|
1571
|
+
state: {
|
|
1572
|
+
dehydratedMatches: this.state.matches.map(d => pick(d, ['fetchedAt', 'invalid', 'invalidAt', 'id', 'loaderData', 'status', 'updatedAt']))
|
|
1573
|
+
}
|
|
1563
1574
|
};
|
|
1564
1575
|
};
|
|
1565
1576
|
hydrate = async __do_not_use_server_ctx => {
|
|
@@ -1572,16 +1583,27 @@
|
|
|
1572
1583
|
const ctx = _ctx;
|
|
1573
1584
|
this.dehydratedData = ctx.payload;
|
|
1574
1585
|
this.options.hydrate?.(ctx.payload);
|
|
1575
|
-
const
|
|
1586
|
+
const {
|
|
1587
|
+
dehydratedMatches
|
|
1588
|
+
} = ctx.router.state;
|
|
1589
|
+
let matches = this.matchRoutes(this.state.location.pathname, this.state.location.search).map(match => {
|
|
1590
|
+
const dehydratedMatch = dehydratedMatches.find(d => d.id === match.id);
|
|
1591
|
+
invariant(dehydratedMatch, `Could not find a client-side match for dehydrated match with id: ${match.id}!`);
|
|
1592
|
+
if (dehydratedMatch) {
|
|
1593
|
+
return {
|
|
1594
|
+
...match,
|
|
1595
|
+
...dehydratedMatch
|
|
1596
|
+
};
|
|
1597
|
+
}
|
|
1598
|
+
return match;
|
|
1599
|
+
});
|
|
1576
1600
|
this.__store.setState(s => {
|
|
1577
1601
|
return {
|
|
1578
1602
|
...s,
|
|
1579
|
-
|
|
1580
|
-
|
|
1603
|
+
matches,
|
|
1604
|
+
matchesById: this.#mergeMatches(s.matchesById, matches)
|
|
1581
1605
|
};
|
|
1582
1606
|
});
|
|
1583
|
-
await this.load();
|
|
1584
|
-
return;
|
|
1585
1607
|
};
|
|
1586
1608
|
injectedHtml = [];
|
|
1587
1609
|
injectHtml = async html => {
|
|
@@ -1594,10 +1616,10 @@
|
|
|
1594
1616
|
const id = `__TSR_DEHYDRATED__${strKey}`;
|
|
1595
1617
|
const data = typeof getData === 'function' ? await getData() : getData;
|
|
1596
1618
|
return `<script id='${id}' suppressHydrationWarning>window["__TSR_DEHYDRATED__${escapeJSON(strKey)}"] = ${JSON.stringify(data)}
|
|
1597
|
-
;(() => {
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
})()
|
|
1619
|
+
// ;(() => {
|
|
1620
|
+
// var el = document.getElementById('${id}')
|
|
1621
|
+
// el.parentElement.removeChild(el)
|
|
1622
|
+
// })()
|
|
1601
1623
|
</script>`;
|
|
1602
1624
|
});
|
|
1603
1625
|
return () => this.hydrateData(key);
|
|
@@ -1618,7 +1640,7 @@
|
|
|
1618
1640
|
// ?.__promisesByKey[key]?.resolve(value)
|
|
1619
1641
|
// }
|
|
1620
1642
|
|
|
1621
|
-
#
|
|
1643
|
+
#processRoutes = routeTree => {
|
|
1622
1644
|
this.routeTree = routeTree;
|
|
1623
1645
|
this.routesById = {};
|
|
1624
1646
|
this.routesByPath = {};
|
|
@@ -1810,7 +1832,7 @@
|
|
|
1810
1832
|
const route = this.getRoute(match.routeId);
|
|
1811
1833
|
const updatedAt = opts?.updatedAt ?? Date.now();
|
|
1812
1834
|
const preloadInvalidAt = updatedAt + (opts?.maxAge ?? route.options.preloadMaxAge ?? this.options.defaultPreloadMaxAge ?? 5000);
|
|
1813
|
-
const invalidAt = updatedAt + (opts?.maxAge ?? route.options.maxAge ?? this.options.defaultMaxAge ??
|
|
1835
|
+
const invalidAt = updatedAt + (opts?.maxAge ?? route.options.maxAge ?? this.options.defaultMaxAge ?? 9999999999999);
|
|
1814
1836
|
this.setRouteMatch(id, s => ({
|
|
1815
1837
|
...s,
|
|
1816
1838
|
error: undefined,
|
|
@@ -2030,6 +2052,28 @@
|
|
|
2030
2052
|
}
|
|
2031
2053
|
}
|
|
2032
2054
|
|
|
2055
|
+
function defer(_promise) {
|
|
2056
|
+
const promise = _promise;
|
|
2057
|
+
if (!promise.__deferredState) {
|
|
2058
|
+
promise.__deferredState = {
|
|
2059
|
+
uid: Math.random().toString(36).slice(2),
|
|
2060
|
+
status: 'pending'
|
|
2061
|
+
};
|
|
2062
|
+
const state = promise.__deferredState;
|
|
2063
|
+
promise.then(data => {
|
|
2064
|
+
state.status = 'success';
|
|
2065
|
+
state.data = data;
|
|
2066
|
+
}).catch(error => {
|
|
2067
|
+
state.status = 'error';
|
|
2068
|
+
state.error = error;
|
|
2069
|
+
});
|
|
2070
|
+
}
|
|
2071
|
+
return promise;
|
|
2072
|
+
}
|
|
2073
|
+
function isDehydratedDeferred(obj) {
|
|
2074
|
+
return typeof obj === 'object' && obj !== null && !(obj instanceof Promise) && !obj.then && '__deferredState' in obj;
|
|
2075
|
+
}
|
|
2076
|
+
|
|
2033
2077
|
exports.FileRoute = FileRoute;
|
|
2034
2078
|
exports.PathParamError = PathParamError;
|
|
2035
2079
|
exports.RootRoute = RootRoute;
|
|
@@ -2045,10 +2089,12 @@
|
|
|
2045
2089
|
exports.decode = decode;
|
|
2046
2090
|
exports.defaultParseSearch = defaultParseSearch;
|
|
2047
2091
|
exports.defaultStringifySearch = defaultStringifySearch;
|
|
2092
|
+
exports.defer = defer;
|
|
2048
2093
|
exports.encode = encode;
|
|
2049
2094
|
exports.functionalUpdate = functionalUpdate;
|
|
2050
2095
|
exports.interpolatePath = interpolatePath;
|
|
2051
2096
|
exports.invariant = invariant;
|
|
2097
|
+
exports.isDehydratedDeferred = isDehydratedDeferred;
|
|
2052
2098
|
exports.isPlainObject = isPlainObject;
|
|
2053
2099
|
exports.isRedirect = isRedirect;
|
|
2054
2100
|
exports.joinPaths = joinPaths;
|