@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
package/dist/esm/router.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { loadRouteChunk, ActivePreload, LoadTransaction, LoaderFlight, PendingSession } from './load-client.js';
|
|
2
1
|
import { LRUCache } from './lru-cache.js';
|
|
3
2
|
import { ProcessRouteTreeResult, ProcessedTree } from './new-process-route-tree.js';
|
|
4
3
|
import { SearchParser, SearchSerializer } from './searchParams.js';
|
|
5
4
|
import { AnyRedirect, ResolvedRedirect } from './redirect.js';
|
|
5
|
+
import { LoadTransaction, LoaderFlight, PendingSession } from './load-client.js';
|
|
6
6
|
import { ServerLoadResult } from './load-server.js';
|
|
7
7
|
import { HistoryAction, HistoryLocation, HistoryState, ParsedHistoryState, RouterHistory } from '@tanstack/history';
|
|
8
8
|
import { Awaitable, Constrain, NoInfer, NonNullableUpdater, PickAsRequired, Updater } from './utils.js';
|
|
@@ -482,10 +482,9 @@ export type LoadFn = (opts?: {
|
|
|
482
482
|
type: HistoryAction;
|
|
483
483
|
};
|
|
484
484
|
_signal?: AbortSignal;
|
|
485
|
-
_dedupe?: boolean;
|
|
486
485
|
}) => Promise<void>;
|
|
487
486
|
export type CommitLocationFn = ({ viewTransition, ignoreBlocker, ...next }: ParsedLocation & CommitLocationOptions) => Promise<void>;
|
|
488
|
-
export type StartTransitionFn = (fn: () => void, expected: Array<AnyRouteMatch
|
|
487
|
+
export type StartTransitionFn = (fn: () => void, expected: Array<AnyRouteMatch>) => Promise<boolean>;
|
|
489
488
|
export interface MatchRoutesFn {
|
|
490
489
|
(pathname: string, locationSearch?: AnySchema, opts?: MatchRoutesOpts): Array<MakeRouteMatchUnion>;
|
|
491
490
|
/**
|
|
@@ -602,8 +601,8 @@ export interface RouterCore<in out TRouteTree extends AnyRoute, in out TTrailing
|
|
|
602
601
|
_tx?: LoadTransaction;
|
|
603
602
|
/** Joinable in-flight loader generations keyed by match ID. */
|
|
604
603
|
_flights?: Map<string, LoaderFlight>;
|
|
605
|
-
/**
|
|
606
|
-
_preloads?: Map<
|
|
604
|
+
/** Active speculative lanes retained for cancellation, invalidation, and cache clearing. */
|
|
605
|
+
_preloads?: Map<AbortController, Array<AnyRouteMatch>>;
|
|
607
606
|
/** Owns cancellable work before a client transaction publishes. */
|
|
608
607
|
_preflight?: AbortController;
|
|
609
608
|
/** Transfers one reconstructed SSR prefix into its initial client load. */
|
|
@@ -612,8 +611,11 @@ export interface RouterCore<in out TRouteTree extends AnyRoute, in out TTrailing
|
|
|
612
611
|
_pending?: PendingSession;
|
|
613
612
|
/** Result of the latest server load, used to render or redirect. */
|
|
614
613
|
_serverResult?: ServerLoadResult;
|
|
615
|
-
/** Framework
|
|
616
|
-
_rendered?:
|
|
614
|
+
/** Framework publication waiting for an exact render acknowledgement. */
|
|
615
|
+
_rendered?: [
|
|
616
|
+
offered?: Array<AnyRouteMatch>,
|
|
617
|
+
settle?: (rendered: boolean) => void
|
|
618
|
+
];
|
|
617
619
|
/** Development-only HMR reload for a route and its descendants. */
|
|
618
620
|
_refreshRoute: (() => Promise<void>) | undefined;
|
|
619
621
|
/** Development-only replacement for a route's lazy chunk owner. */
|
|
@@ -733,9 +735,11 @@ export declare class RouterCore<in out TRouteTree extends AnyRoute, in out TTrai
|
|
|
733
735
|
load: LoadFn;
|
|
734
736
|
startViewTransition: (fn: () => Promise<void>) => any;
|
|
735
737
|
/**
|
|
736
|
-
* Invalidate
|
|
738
|
+
* Invalidate selected match generations and optionally force current matches
|
|
739
|
+
* back into a pending state.
|
|
737
740
|
*
|
|
738
|
-
* - Marks
|
|
741
|
+
* - Marks committed and cached matches whose IDs are selected as invalid.
|
|
742
|
+
* - Retires selected active preloads so older work cannot publish fresh data.
|
|
739
743
|
*
|
|
740
744
|
* The next load decides when to publish pending UI, so invalidation does not
|
|
741
745
|
* mutate the currently rendered status.
|
|
@@ -743,7 +747,7 @@ export declare class RouterCore<in out TRouteTree extends AnyRoute, in out TTrai
|
|
|
743
747
|
invalidate: InvalidateFn<RouterCore<TRouteTree, TTrailingSlashOption, TDefaultStructuralSharingOption, TRouterHistory, TDehydrated>>;
|
|
744
748
|
resolveRedirect: (redirect: AnyRedirect) => AnyRedirect;
|
|
745
749
|
clearCache: ClearCacheFn<this>;
|
|
746
|
-
loadRouteChunk:
|
|
750
|
+
loadRouteChunk: (route: AnyRoute, componentType?: 'errorComponent' | 'notFoundComponent' | false) => Promise<void> | undefined;
|
|
747
751
|
preloadRoute: PreloadRouteFn<TRouteTree, TTrailingSlashOption, TDefaultStructuralSharingOption, TRouterHistory>;
|
|
748
752
|
matchRoute: MatchRouteFn<TRouteTree, TTrailingSlashOption, TDefaultStructuralSharingOption, TRouterHistory>;
|
|
749
753
|
ssr?: {
|
package/dist/esm/router.js
CHANGED
|
@@ -7,7 +7,7 @@ import { setupScrollRestoration } from "./scroll-restoration.js";
|
|
|
7
7
|
import { defaultParseSearch, defaultStringifySearch } from "./searchParams.js";
|
|
8
8
|
import { rootRouteId } from "./root.js";
|
|
9
9
|
import { isRedirect } from "./redirect.js";
|
|
10
|
-
import { loadClientRoute, loadRouteChunk, preloadClientRoute, refreshClientRoute, replaceRouteChunk
|
|
10
|
+
import { loadClientRoute, loadRouteChunk, preloadClientRoute, refreshClientRoute, replaceRouteChunk } from "./load-client.js";
|
|
11
11
|
import { composeRewrites, executeRewriteInput, executeRewriteOutput, rewriteBasepath } from "./rewrite.js";
|
|
12
12
|
import { createRouterStores } from "./stores.js";
|
|
13
13
|
import { createBrowserHistory, parseHref } from "@tanstack/history";
|
|
@@ -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 = loadRouteChunk;
|
|
584
605
|
this.preloadRoute = (opts) => preloadClientRoute(this, opts);
|
|
@@ -928,6 +949,6 @@ function extractStrictParams(route, accumulatedParams) {
|
|
|
928
949
|
if (parseParams) Object.assign(accumulatedParams, parseParams(accumulatedParams));
|
|
929
950
|
}
|
|
930
951
|
//#endregion
|
|
931
|
-
export { PathParamError, RouterCore, SearchParamError,
|
|
952
|
+
export { PathParamError, RouterCore, SearchParamError, defaultSerializeError, getInitialRouterState, getLocationChangeInfo, lazyFn, runRouteLifecycle, trailingSlashOptions };
|
|
932
953
|
|
|
933
954
|
//# sourceMappingURL=router.js.map
|