@tanstack/router-core 1.171.16-pre.0 → 1.171.16
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/link.cjs.map +1 -1
- package/dist/cjs/link.d.cts +5 -3
- package/dist/cjs/load-client.cjs +169 -246
- package/dist/cjs/load-client.cjs.map +1 -1
- package/dist/cjs/load-client.d.cts +10 -39
- package/dist/cjs/router.cjs +42 -22
- package/dist/cjs/router.cjs.map +1 -1
- package/dist/cjs/router.d.cts +14 -10
- package/dist/esm/link.d.ts +5 -3
- package/dist/esm/link.js.map +1 -1
- package/dist/esm/load-client.d.ts +10 -39
- package/dist/esm/load-client.js +171 -247
- package/dist/esm/load-client.js.map +1 -1
- package/dist/esm/router.d.ts +14 -10
- package/dist/esm/router.js +44 -23
- package/dist/esm/router.js.map +1 -1
- package/package.json +1 -1
- package/skills/router-core/SKILL.md +23 -4
- package/skills/router-core/auth-and-guards/SKILL.md +10 -10
- package/skills/router-core/code-splitting/SKILL.md +5 -4
- package/skills/router-core/data-loading/SKILL.md +30 -18
- package/skills/router-core/navigation/SKILL.md +5 -4
- package/skills/router-core/not-found-and-errors/SKILL.md +5 -4
- package/skills/router-core/path-params/SKILL.md +5 -4
- package/skills/router-core/search-params/SKILL.md +5 -4
- package/skills/router-core/ssr/SKILL.md +5 -4
- package/skills/router-core/type-safety/SKILL.md +11 -4
- package/src/link.ts +5 -3
- package/src/load-client.ts +582 -632
- package/src/router.ts +87 -44
|
@@ -7,7 +7,7 @@ import { AnyRoute } from './route.cjs';
|
|
|
7
7
|
import { AnyRedirect } from './redirect.cjs';
|
|
8
8
|
import { AnyRouter } from './router.cjs';
|
|
9
9
|
export declare function replaceRouteChunk(route: AnyRoute, lazyFn: AnyRoute['lazyFn']): void;
|
|
10
|
-
export declare function loadRouteChunk(route: AnyRoute, componentType?: 'errorComponent' | 'notFoundComponent' | false): Promise<void> | undefined;
|
|
10
|
+
export declare function loadRouteChunk(route: AnyRoute, componentType?: 'errorComponent' | 'notFoundComponent' | false, onPendingReady?: () => void): Promise<void> | undefined;
|
|
11
11
|
/** Return the structural lane through the first terminal render boundary. */
|
|
12
12
|
export declare function _getRenderedMatches(matches: Array<AnyRouteMatch>): Array<AnyRouteMatch>;
|
|
13
13
|
/** Return the lane whose document assets belong to the current presentation. */
|
|
@@ -37,7 +37,7 @@ declare const ERROR = 1;
|
|
|
37
37
|
declare const NOT_FOUND = 2;
|
|
38
38
|
declare const REDIRECTED = 3;
|
|
39
39
|
declare const CANCELED = 4;
|
|
40
|
-
type LoaderOutcome = [typeof SUCCESS, data: unknown] | [typeof ERROR, error: unknown] | [typeof NOT_FOUND, error: NotFoundError] | [typeof REDIRECTED, redirect: AnyRedirect] | [typeof CANCELED];
|
|
40
|
+
type LoaderOutcome = [kind: typeof SUCCESS, data: unknown] | [kind: typeof ERROR, error: unknown] | [kind: typeof NOT_FOUND, error: NotFoundError] | [kind: typeof REDIRECTED, redirect: AnyRedirect] | [kind: typeof CANCELED];
|
|
41
41
|
type IndexedOutcome = [index: number, outcome: LoaderOutcome, boundary?: number];
|
|
42
42
|
export type LoaderFlight = [
|
|
43
43
|
outcome: Promise<LoaderOutcome>,
|
|
@@ -58,27 +58,6 @@ declare const matchPhase: unique symbol;
|
|
|
58
58
|
type SettledMatch = WorkMatch & {
|
|
59
59
|
readonly [matchPhase]: 'settled';
|
|
60
60
|
};
|
|
61
|
-
export type LaneInputs = [
|
|
62
|
-
routeTree: AnyRoute,
|
|
63
|
-
context: unknown,
|
|
64
|
-
additionalContext: unknown,
|
|
65
|
-
state: object,
|
|
66
|
-
search: object,
|
|
67
|
-
maskedLocation: [
|
|
68
|
-
href: string,
|
|
69
|
-
state: object,
|
|
70
|
-
search: object,
|
|
71
|
-
unmaskOnReload: boolean | undefined
|
|
72
|
-
] | undefined
|
|
73
|
-
];
|
|
74
|
-
export type ActivePreload = [
|
|
75
|
-
matches: Array<AnyRouteMatch>,
|
|
76
|
-
controller: AbortController,
|
|
77
|
-
result: Promise<LaneResult>,
|
|
78
|
-
semanticOwner: Array<AnyRouteMatch>,
|
|
79
|
-
inputs: LaneInputs,
|
|
80
|
-
redirects: number
|
|
81
|
-
];
|
|
82
61
|
export type LoadTransaction = [
|
|
83
62
|
controller: AbortController,
|
|
84
63
|
redirects: number,
|
|
@@ -88,12 +67,14 @@ export type LoadTransaction = [
|
|
|
88
67
|
done: Promise<void>,
|
|
89
68
|
/**
|
|
90
69
|
* Dev-only HMR refresh mode. Presence is the mode flag; a refresh always
|
|
91
|
-
* carries the presentation it started from
|
|
92
|
-
*
|
|
70
|
+
* carries the presentation it started from and its optional hydration
|
|
71
|
+
* handoff. While a publication awaits acknowledgement, its rollback lives
|
|
72
|
+
* with the transaction that owns the publication.
|
|
93
73
|
*/
|
|
94
74
|
refresh?: [
|
|
95
75
|
presentation: Array<AnyRouteMatch>,
|
|
96
|
-
handoff: NonNullable<AnyRouter['_handoff']> | undefined
|
|
76
|
+
handoff: NonNullable<AnyRouter['_handoff']> | undefined,
|
|
77
|
+
rollback?: () => boolean
|
|
97
78
|
]
|
|
98
79
|
];
|
|
99
80
|
export type PendingSession = [
|
|
@@ -106,34 +87,24 @@ export type PendingSession = [
|
|
|
106
87
|
component?: unknown
|
|
107
88
|
];
|
|
108
89
|
type CoordinatorRouter = AnyRouter & {
|
|
109
|
-
/**
|
|
110
|
-
_preloads?: Map<
|
|
90
|
+
/** Active speculative lanes retained for cancellation, invalidation, and cache clearing. */
|
|
91
|
+
_preloads?: Map<AbortController, Array<AnyRouteMatch>>;
|
|
111
92
|
_refreshNextLoad?: boolean;
|
|
112
|
-
_rollbackRefresh?: () => void;
|
|
113
93
|
_cancelTransition?: () => void;
|
|
114
94
|
};
|
|
115
95
|
type BackgroundLoaderTask = [
|
|
116
96
|
index: number,
|
|
117
97
|
outcome: Promise<LoaderOutcome>,
|
|
118
|
-
|
|
98
|
+
chunkFailure: Promise<IndexedOutcome | undefined>,
|
|
119
99
|
candidate: WorkMatch
|
|
120
100
|
];
|
|
121
|
-
type ControlOutcome = [typeof REDIRECTED, redirect: AnyRedirect] | [typeof CANCELED];
|
|
122
|
-
type LaneResult = ProjectedLane | ControlOutcome;
|
|
123
101
|
export declare function waitFor<T>(value: T | PromiseLike<T>, signal: AbortSignal): Promise<T>;
|
|
124
102
|
export declare function getRoute(router: AnyRouter, match: WorkMatch): AnyRoute;
|
|
125
103
|
export declare function navigateFrom(router: AnyRouter, location: ParsedLocation): (opts: any) => Promise<void>;
|
|
126
|
-
export declare function laneInputs(router: AnyRouter, location: ParsedLocation): LaneInputs;
|
|
127
|
-
/**
|
|
128
|
-
* Not passing in a `next` ownership recipient
|
|
129
|
-
* is equivalent to discarding the match resources
|
|
130
|
-
*/
|
|
131
|
-
export declare function transferMatchResources(router: AnyRouter, previous: Array<AnyRouteMatch>, next?: Array<AnyRouteMatch>): void;
|
|
132
104
|
export declare function cacheLoaderMatch(router: CoordinatorRouter, match: SettledMatch, planned: AnyRouteMatch | undefined): void;
|
|
133
105
|
export declare function projectLane(router: AnyRouter, lane: ReducedLane, signal: AbortSignal, start?: number, end?: number): Promise<ProjectedLane>;
|
|
134
106
|
export declare function loadClientRoute(router: CoordinatorRouter, opts?: {
|
|
135
107
|
sync?: boolean;
|
|
136
|
-
_dedupe?: boolean;
|
|
137
108
|
}): Promise<void>;
|
|
138
109
|
export declare function refreshClientRoute(router: CoordinatorRouter): Promise<void>;
|
|
139
110
|
export declare function preloadClientRoute(router: CoordinatorRouter, opts: any, redirects?: number): Promise<Array<AnyRouteMatch> | undefined>;
|
package/dist/cjs/router.cjs
CHANGED
|
@@ -387,7 +387,7 @@ var RouterCore = class {
|
|
|
387
387
|
previousCommitPromise?.resolve();
|
|
388
388
|
};
|
|
389
389
|
this._commitPromise = commitPromise;
|
|
390
|
-
if (isSameLocation) this.load(
|
|
390
|
+
if (isSameLocation) this.load();
|
|
391
391
|
else {
|
|
392
392
|
let { maskedLocation, hashScrollIntoView, ...nextHistory } = next;
|
|
393
393
|
if (maskedLocation) {
|
|
@@ -518,9 +518,20 @@ var RouterCore = class {
|
|
|
518
518
|
this.invalidate = (opts) => {
|
|
519
519
|
const committedMatches = this._committed;
|
|
520
520
|
const filter = opts?.filter;
|
|
521
|
-
const
|
|
521
|
+
const preloads = this._preloads;
|
|
522
|
+
const invalidIds = new Set([
|
|
523
|
+
...committedMatches,
|
|
524
|
+
...this._cache.values(),
|
|
525
|
+
...[...preloads?.values() ?? []].flat(),
|
|
526
|
+
...this._tx?.[3] ?? []
|
|
527
|
+
].filter((match) => !filter || filter(match)).map((match) => match.id));
|
|
528
|
+
const discardedPreloads = [];
|
|
529
|
+
for (const [controller, matches] of preloads ?? []) if (matches.some((match) => invalidIds.has(match.id))) {
|
|
530
|
+
preloads.delete(controller);
|
|
531
|
+
discardedPreloads.push(controller);
|
|
532
|
+
}
|
|
522
533
|
const invalidate = (d) => {
|
|
523
|
-
if (
|
|
534
|
+
if (invalidIds.has(d.id)) {
|
|
524
535
|
const route = this.routesById[d.routeId];
|
|
525
536
|
const next = {
|
|
526
537
|
...d,
|
|
@@ -535,11 +546,13 @@ var RouterCore = class {
|
|
|
535
546
|
}
|
|
536
547
|
return d;
|
|
537
548
|
};
|
|
538
|
-
|
|
539
|
-
this.
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
549
|
+
this._committed = committedMatches.map(invalidate);
|
|
550
|
+
for (const [id, match] of this._cache) if (invalidIds.has(id)) {
|
|
551
|
+
match.invalid = true;
|
|
552
|
+
if (opts?.forcePending) match.status = "pending";
|
|
553
|
+
}
|
|
554
|
+
for (const id of invalidIds) this._flights?.delete(id);
|
|
555
|
+
for (const controller of discardedPreloads) controller.abort();
|
|
543
556
|
this.shouldViewTransition = false;
|
|
544
557
|
return this.load({ sync: opts?.sync });
|
|
545
558
|
};
|
|
@@ -565,20 +578,28 @@ var RouterCore = class {
|
|
|
565
578
|
const cached = this._cache;
|
|
566
579
|
const preloads = this._preloads;
|
|
567
580
|
const filter = opts?.filter;
|
|
568
|
-
const retained = /* @__PURE__ */ new Map();
|
|
569
581
|
const discarded = [];
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
for (const
|
|
582
|
+
const discardedIds = [];
|
|
583
|
+
for (const [id, match] of cached) if (!filter || filter(match)) {
|
|
584
|
+
discardedIds.push(id);
|
|
585
|
+
discarded.push(match);
|
|
586
|
+
}
|
|
587
|
+
const abort = [];
|
|
588
|
+
for (const [controller, matches] of preloads ?? []) if (!filter || matches.some(filter)) {
|
|
589
|
+
abort.push(controller);
|
|
590
|
+
discarded.push(...matches);
|
|
591
|
+
}
|
|
592
|
+
for (const id of discardedIds) cached.delete(id);
|
|
593
|
+
for (const controller of abort) preloads.delete(controller);
|
|
594
|
+
for (const match of discarded) {
|
|
595
|
+
const flight = match._flight;
|
|
596
|
+
match._flight = void 0;
|
|
597
|
+
if (flight && !--flight[2]) {
|
|
598
|
+
if (this._flights?.get(match.id) === flight) this._flights.delete(match.id);
|
|
599
|
+
abort.push(flight[1]);
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
for (const controller of abort) controller.abort();
|
|
582
603
|
};
|
|
583
604
|
this.loadRouteChunk = require_load_client.loadRouteChunk;
|
|
584
605
|
this.preloadRoute = (opts) => require_load_client.preloadClientRoute(this, opts);
|
|
@@ -931,7 +952,6 @@ function extractStrictParams(route, accumulatedParams) {
|
|
|
931
952
|
exports.PathParamError = PathParamError;
|
|
932
953
|
exports.RouterCore = RouterCore;
|
|
933
954
|
exports.SearchParamError = SearchParamError;
|
|
934
|
-
exports._getUserHistoryState = _getUserHistoryState;
|
|
935
955
|
exports.defaultSerializeError = defaultSerializeError;
|
|
936
956
|
exports.getInitialRouterState = getInitialRouterState;
|
|
937
957
|
exports.getLocationChangeInfo = getLocationChangeInfo;
|