@tanstack/router-core 1.168.9 → 1.168.10
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/hash-scroll.cjs +1 -1
- package/dist/cjs/hash-scroll.cjs.map +1 -1
- package/dist/cjs/index.d.cts +1 -1
- package/dist/cjs/load-matches.cjs +4 -4
- package/dist/cjs/load-matches.cjs.map +1 -1
- package/dist/cjs/router.cjs +44 -45
- package/dist/cjs/router.cjs.map +1 -1
- package/dist/cjs/router.d.cts +3 -1
- package/dist/cjs/scroll-restoration.cjs +1 -1
- package/dist/cjs/scroll-restoration.cjs.map +1 -1
- package/dist/cjs/ssr/createRequestHandler.cjs +2 -2
- package/dist/cjs/ssr/createRequestHandler.cjs.map +1 -1
- package/dist/cjs/ssr/serializer/RawStream.cjs +41 -32
- package/dist/cjs/ssr/serializer/RawStream.cjs.map +1 -1
- package/dist/cjs/ssr/serializer/RawStream.d.cts +12 -4
- package/dist/cjs/ssr/serializer/ShallowErrorPlugin.cjs.map +1 -1
- package/dist/cjs/ssr/serializer/ShallowErrorPlugin.d.cts +2 -2
- package/dist/cjs/ssr/serializer/seroval-plugins.cjs.map +1 -1
- package/dist/cjs/ssr/serializer/seroval-plugins.d.cts +2 -1
- package/dist/cjs/ssr/serializer/transformer.cjs +16 -14
- package/dist/cjs/ssr/serializer/transformer.cjs.map +1 -1
- package/dist/cjs/ssr/serializer/transformer.d.cts +24 -23
- package/dist/cjs/ssr/ssr-client.cjs +8 -8
- package/dist/cjs/ssr/ssr-client.cjs.map +1 -1
- package/dist/cjs/ssr/ssr-server.cjs +31 -9
- package/dist/cjs/ssr/ssr-server.cjs.map +1 -1
- package/dist/cjs/ssr/ssr-server.d.cts +3 -2
- package/dist/cjs/ssr/transformStreamWithRouter.cjs +4 -1
- package/dist/cjs/ssr/transformStreamWithRouter.cjs.map +1 -1
- package/dist/cjs/stores.cjs +27 -27
- package/dist/cjs/stores.cjs.map +1 -1
- package/dist/cjs/stores.d.cts +2 -2
- package/dist/esm/hash-scroll.js +1 -1
- package/dist/esm/hash-scroll.js.map +1 -1
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/load-matches.js +4 -4
- package/dist/esm/load-matches.js.map +1 -1
- package/dist/esm/router.d.ts +3 -1
- package/dist/esm/router.js +44 -45
- package/dist/esm/router.js.map +1 -1
- package/dist/esm/scroll-restoration.js +1 -1
- package/dist/esm/scroll-restoration.js.map +1 -1
- package/dist/esm/ssr/createRequestHandler.js +2 -2
- package/dist/esm/ssr/createRequestHandler.js.map +1 -1
- package/dist/esm/ssr/serializer/RawStream.d.ts +12 -4
- package/dist/esm/ssr/serializer/RawStream.js +41 -32
- package/dist/esm/ssr/serializer/RawStream.js.map +1 -1
- package/dist/esm/ssr/serializer/ShallowErrorPlugin.d.ts +2 -2
- package/dist/esm/ssr/serializer/ShallowErrorPlugin.js.map +1 -1
- package/dist/esm/ssr/serializer/seroval-plugins.d.ts +2 -1
- package/dist/esm/ssr/serializer/seroval-plugins.js.map +1 -1
- package/dist/esm/ssr/serializer/transformer.d.ts +24 -23
- package/dist/esm/ssr/serializer/transformer.js +16 -14
- package/dist/esm/ssr/serializer/transformer.js.map +1 -1
- package/dist/esm/ssr/ssr-client.js +8 -8
- package/dist/esm/ssr/ssr-client.js.map +1 -1
- package/dist/esm/ssr/ssr-server.d.ts +3 -2
- package/dist/esm/ssr/ssr-server.js +31 -9
- package/dist/esm/ssr/ssr-server.js.map +1 -1
- package/dist/esm/ssr/transformStreamWithRouter.js +4 -1
- package/dist/esm/ssr/transformStreamWithRouter.js.map +1 -1
- package/dist/esm/stores.d.ts +2 -2
- package/dist/esm/stores.js +28 -28
- package/dist/esm/stores.js.map +1 -1
- package/package.json +3 -3
- package/src/hash-scroll.ts +1 -1
- package/src/index.ts +1 -1
- package/src/load-matches.ts +6 -6
- package/src/router.ts +59 -57
- package/src/scroll-restoration.ts +1 -1
- package/src/ssr/createRequestHandler.ts +4 -5
- package/src/ssr/serializer/RawStream.ts +65 -56
- package/src/ssr/serializer/ShallowErrorPlugin.ts +2 -2
- package/src/ssr/serializer/seroval-plugins.ts +2 -1
- package/src/ssr/serializer/transformer.ts +71 -76
- package/src/ssr/ssr-client.ts +7 -11
- package/src/ssr/ssr-server.ts +39 -7
- package/src/ssr/transformStreamWithRouter.ts +3 -0
- package/src/stores.ts +34 -34
package/dist/esm/router.js
CHANGED
|
@@ -130,7 +130,7 @@ var RouterCore = class {
|
|
|
130
130
|
if (this.history) this.updateLatestLocation();
|
|
131
131
|
needsLocationUpdate = true;
|
|
132
132
|
}
|
|
133
|
-
if (needsLocationUpdate && this.stores) this.stores.location.
|
|
133
|
+
if (needsLocationUpdate && this.stores) this.stores.location.set(this.latestLocation);
|
|
134
134
|
if (typeof window !== "undefined" && "CSS" in window && typeof window.CSS?.supports === "function") this.isViewTransitionTypesSupported = window.CSS.supports("selector(:active-view-transition-type(a)");
|
|
135
135
|
};
|
|
136
136
|
this.updateLatestLocation = () => {
|
|
@@ -234,12 +234,12 @@ var RouterCore = class {
|
|
|
234
234
|
match._nonReactive.pendingTimeout = void 0;
|
|
235
235
|
};
|
|
236
236
|
this.cancelMatches = () => {
|
|
237
|
-
this.stores.pendingMatchesId.
|
|
237
|
+
this.stores.pendingMatchesId.get().forEach((matchId) => {
|
|
238
238
|
this.cancelMatch(matchId);
|
|
239
239
|
});
|
|
240
|
-
this.stores.matchesId.
|
|
240
|
+
this.stores.matchesId.get().forEach((matchId) => {
|
|
241
241
|
if (this.stores.pendingMatchStoresById.has(matchId)) return;
|
|
242
|
-
const match = this.stores.activeMatchStoresById.get(matchId)?.
|
|
242
|
+
const match = this.stores.activeMatchStoresById.get(matchId)?.get();
|
|
243
243
|
if (!match) return;
|
|
244
244
|
if (match.status === "pending" || match.isFetching === "loader") this.cancelMatch(matchId);
|
|
245
245
|
});
|
|
@@ -507,12 +507,12 @@ var RouterCore = class {
|
|
|
507
507
|
}
|
|
508
508
|
}
|
|
509
509
|
const pendingMatches = this.matchRoutes(this.latestLocation);
|
|
510
|
-
const nextCachedMatches = this.stores.cachedMatchesSnapshot.
|
|
510
|
+
const nextCachedMatches = this.stores.cachedMatchesSnapshot.get().filter((d) => !pendingMatches.some((e) => e.id === d.id));
|
|
511
511
|
this.batch(() => {
|
|
512
|
-
this.stores.status.
|
|
513
|
-
this.stores.statusCode.
|
|
514
|
-
this.stores.isLoading.
|
|
515
|
-
this.stores.location.
|
|
512
|
+
this.stores.status.set("pending");
|
|
513
|
+
this.stores.statusCode.set(200);
|
|
514
|
+
this.stores.isLoading.set(true);
|
|
515
|
+
this.stores.location.set(this.latestLocation);
|
|
516
516
|
this.stores.setPendingMatches(pendingMatches);
|
|
517
517
|
this.stores.setCachedMatches(nextCachedMatches);
|
|
518
518
|
});
|
|
@@ -521,15 +521,14 @@ var RouterCore = class {
|
|
|
521
521
|
let redirect;
|
|
522
522
|
let notFound;
|
|
523
523
|
let loadPromise;
|
|
524
|
-
const previousLocation = this.stores.resolvedLocation.
|
|
524
|
+
const previousLocation = this.stores.resolvedLocation.get() ?? this.stores.location.get();
|
|
525
525
|
loadPromise = new Promise((resolve) => {
|
|
526
526
|
this.startTransition(async () => {
|
|
527
527
|
try {
|
|
528
528
|
this.beforeLoad();
|
|
529
529
|
const next = this.latestLocation;
|
|
530
|
-
const
|
|
531
|
-
|
|
532
|
-
if (!this.stores.redirect.state) this.emit({
|
|
530
|
+
const locationChangeInfo = getLocationChangeInfo(next, this.stores.resolvedLocation.get());
|
|
531
|
+
if (!this.stores.redirect.get()) this.emit({
|
|
533
532
|
type: "onBeforeNavigate",
|
|
534
533
|
...locationChangeInfo
|
|
535
534
|
});
|
|
@@ -541,7 +540,7 @@ var RouterCore = class {
|
|
|
541
540
|
router: this,
|
|
542
541
|
sync: opts?.sync,
|
|
543
542
|
forceStaleReload: previousLocation.href === next.href,
|
|
544
|
-
matches: this.stores.pendingMatchesSnapshot.
|
|
543
|
+
matches: this.stores.pendingMatchesSnapshot.get(),
|
|
545
544
|
location: next,
|
|
546
545
|
updateMatch: this.updateMatch,
|
|
547
546
|
onReady: async () => {
|
|
@@ -552,9 +551,9 @@ var RouterCore = class {
|
|
|
552
551
|
let hookEnteringMatches = null;
|
|
553
552
|
let hookStayingMatches = null;
|
|
554
553
|
this.batch(() => {
|
|
555
|
-
const pendingMatches = this.stores.pendingMatchesSnapshot.
|
|
554
|
+
const pendingMatches = this.stores.pendingMatchesSnapshot.get();
|
|
556
555
|
const mountPending = pendingMatches.length;
|
|
557
|
-
const currentMatches = this.stores.activeMatchesSnapshot.
|
|
556
|
+
const currentMatches = this.stores.activeMatchesSnapshot.get();
|
|
558
557
|
exitingMatches = mountPending ? currentMatches.filter((match) => !this.stores.pendingMatchStoresById.has(match.id)) : null;
|
|
559
558
|
const pendingRouteIds = /* @__PURE__ */ new Set();
|
|
560
559
|
for (const s of this.stores.pendingMatchStoresById.values()) if (s.routeId) pendingRouteIds.add(s.routeId);
|
|
@@ -563,8 +562,8 @@ var RouterCore = class {
|
|
|
563
562
|
hookExitingMatches = mountPending ? currentMatches.filter((match) => !pendingRouteIds.has(match.routeId)) : null;
|
|
564
563
|
hookEnteringMatches = mountPending ? pendingMatches.filter((match) => !activeRouteIds.has(match.routeId)) : null;
|
|
565
564
|
hookStayingMatches = mountPending ? pendingMatches.filter((match) => activeRouteIds.has(match.routeId)) : currentMatches;
|
|
566
|
-
this.stores.isLoading.
|
|
567
|
-
this.stores.loadedAt.
|
|
565
|
+
this.stores.isLoading.set(false);
|
|
566
|
+
this.stores.loadedAt.set(Date.now());
|
|
568
567
|
/**
|
|
569
568
|
* When committing new matches, cache any exiting matches that are still usable.
|
|
570
569
|
* Routes that resolved with `status: 'error'` or `status: 'notFound'` are
|
|
@@ -574,7 +573,7 @@ var RouterCore = class {
|
|
|
574
573
|
if (mountPending) {
|
|
575
574
|
this.stores.setActiveMatches(pendingMatches);
|
|
576
575
|
this.stores.setPendingMatches([]);
|
|
577
|
-
this.stores.setCachedMatches([...this.stores.cachedMatchesSnapshot.
|
|
576
|
+
this.stores.setCachedMatches([...this.stores.cachedMatchesSnapshot.get(), ...exitingMatches.filter((d) => d.status !== "error" && d.status !== "notFound" && d.status !== "redirected")]);
|
|
578
577
|
this.clearExpiredCache();
|
|
579
578
|
}
|
|
580
579
|
});
|
|
@@ -599,10 +598,10 @@ var RouterCore = class {
|
|
|
599
598
|
ignoreBlocker: true
|
|
600
599
|
});
|
|
601
600
|
} else if (isNotFound(err)) notFound = err;
|
|
602
|
-
const nextStatusCode = redirect ? redirect.status : notFound ? 404 : this.stores.activeMatchesSnapshot.
|
|
601
|
+
const nextStatusCode = redirect ? redirect.status : notFound ? 404 : this.stores.activeMatchesSnapshot.get().some((d) => d.status === "error") ? 500 : 200;
|
|
603
602
|
this.batch(() => {
|
|
604
|
-
this.stores.statusCode.
|
|
605
|
-
this.stores.redirect.
|
|
603
|
+
this.stores.statusCode.set(nextStatusCode);
|
|
604
|
+
this.stores.redirect.set(redirect);
|
|
606
605
|
});
|
|
607
606
|
}
|
|
608
607
|
if (this.latestLoadPromise === loadPromise) {
|
|
@@ -618,8 +617,8 @@ var RouterCore = class {
|
|
|
618
617
|
while (this.latestLoadPromise && loadPromise !== this.latestLoadPromise) await this.latestLoadPromise;
|
|
619
618
|
let newStatusCode = void 0;
|
|
620
619
|
if (this.hasNotFoundMatch()) newStatusCode = 404;
|
|
621
|
-
else if (this.stores.activeMatchesSnapshot.
|
|
622
|
-
if (newStatusCode !== void 0) this.stores.statusCode.
|
|
620
|
+
else if (this.stores.activeMatchesSnapshot.get().some((d) => d.status === "error")) newStatusCode = 500;
|
|
621
|
+
if (newStatusCode !== void 0) this.stores.statusCode.set(newStatusCode);
|
|
623
622
|
};
|
|
624
623
|
this.startViewTransition = (fn) => {
|
|
625
624
|
const shouldViewTransition = this.shouldViewTransition ?? this.options.defaultViewTransition;
|
|
@@ -628,7 +627,7 @@ var RouterCore = class {
|
|
|
628
627
|
let startViewTransitionParams;
|
|
629
628
|
if (typeof shouldViewTransition === "object" && this.isViewTransitionTypesSupported) {
|
|
630
629
|
const next = this.latestLocation;
|
|
631
|
-
const prevLocation = this.stores.resolvedLocation.
|
|
630
|
+
const prevLocation = this.stores.resolvedLocation.get();
|
|
632
631
|
const resolvedViewTransitionTypes = typeof shouldViewTransition.types === "function" ? shouldViewTransition.types(getLocationChangeInfo(next, prevLocation)) : shouldViewTransition.types;
|
|
633
632
|
if (resolvedViewTransitionTypes === false) {
|
|
634
633
|
fn();
|
|
@@ -646,25 +645,25 @@ var RouterCore = class {
|
|
|
646
645
|
this.startTransition(() => {
|
|
647
646
|
const pendingMatch = this.stores.pendingMatchStoresById.get(id);
|
|
648
647
|
if (pendingMatch) {
|
|
649
|
-
pendingMatch.
|
|
648
|
+
pendingMatch.set(updater);
|
|
650
649
|
return;
|
|
651
650
|
}
|
|
652
651
|
const activeMatch = this.stores.activeMatchStoresById.get(id);
|
|
653
652
|
if (activeMatch) {
|
|
654
|
-
activeMatch.
|
|
653
|
+
activeMatch.set(updater);
|
|
655
654
|
return;
|
|
656
655
|
}
|
|
657
656
|
const cachedMatch = this.stores.cachedMatchStoresById.get(id);
|
|
658
657
|
if (cachedMatch) {
|
|
659
|
-
const next = updater(cachedMatch.
|
|
658
|
+
const next = updater(cachedMatch.get());
|
|
660
659
|
if (next.status === "redirected") {
|
|
661
|
-
if (this.stores.cachedMatchStoresById.delete(id)) this.stores.cachedMatchesId.
|
|
662
|
-
} else cachedMatch.
|
|
660
|
+
if (this.stores.cachedMatchStoresById.delete(id)) this.stores.cachedMatchesId.set((prev) => prev.filter((matchId) => matchId !== id));
|
|
661
|
+
} else cachedMatch.set(next);
|
|
663
662
|
}
|
|
664
663
|
});
|
|
665
664
|
};
|
|
666
665
|
this.getMatch = (matchId) => {
|
|
667
|
-
return this.stores.cachedMatchStoresById.get(matchId)?.
|
|
666
|
+
return this.stores.cachedMatchStoresById.get(matchId)?.get() ?? this.stores.pendingMatchStoresById.get(matchId)?.get() ?? this.stores.activeMatchStoresById.get(matchId)?.get();
|
|
668
667
|
};
|
|
669
668
|
this.invalidate = (opts) => {
|
|
670
669
|
const invalidate = (d) => {
|
|
@@ -679,9 +678,9 @@ var RouterCore = class {
|
|
|
679
678
|
return d;
|
|
680
679
|
};
|
|
681
680
|
this.batch(() => {
|
|
682
|
-
this.stores.setActiveMatches(this.stores.activeMatchesSnapshot.
|
|
683
|
-
this.stores.setCachedMatches(this.stores.cachedMatchesSnapshot.
|
|
684
|
-
this.stores.setPendingMatches(this.stores.pendingMatchesSnapshot.
|
|
681
|
+
this.stores.setActiveMatches(this.stores.activeMatchesSnapshot.get().map(invalidate));
|
|
682
|
+
this.stores.setCachedMatches(this.stores.cachedMatchesSnapshot.get().map(invalidate));
|
|
683
|
+
this.stores.setPendingMatches(this.stores.pendingMatchesSnapshot.get().map(invalidate));
|
|
685
684
|
});
|
|
686
685
|
this.shouldViewTransition = false;
|
|
687
686
|
return this.load({ sync: opts?.sync });
|
|
@@ -710,7 +709,7 @@ var RouterCore = class {
|
|
|
710
709
|
};
|
|
711
710
|
this.clearCache = (opts) => {
|
|
712
711
|
const filter = opts?.filter;
|
|
713
|
-
if (filter !== void 0) this.stores.setCachedMatches(this.stores.cachedMatchesSnapshot.
|
|
712
|
+
if (filter !== void 0) this.stores.setCachedMatches(this.stores.cachedMatchesSnapshot.get().filter((m) => !filter(m)));
|
|
714
713
|
else this.stores.setCachedMatches([]);
|
|
715
714
|
};
|
|
716
715
|
this.clearExpiredCache = () => {
|
|
@@ -732,11 +731,11 @@ var RouterCore = class {
|
|
|
732
731
|
preload: true,
|
|
733
732
|
dest: opts
|
|
734
733
|
});
|
|
735
|
-
const activeMatchIds = new Set([...this.stores.matchesId.
|
|
736
|
-
const loadedMatchIds = new Set([...activeMatchIds, ...this.stores.cachedMatchesId.
|
|
734
|
+
const activeMatchIds = new Set([...this.stores.matchesId.get(), ...this.stores.pendingMatchesId.get()]);
|
|
735
|
+
const loadedMatchIds = new Set([...activeMatchIds, ...this.stores.cachedMatchesId.get()]);
|
|
737
736
|
const matchesToCache = matches.filter((match) => !loadedMatchIds.has(match.id));
|
|
738
737
|
if (matchesToCache.length) {
|
|
739
|
-
const cachedMatches = this.stores.cachedMatchesSnapshot.
|
|
738
|
+
const cachedMatches = this.stores.cachedMatchesSnapshot.get();
|
|
740
739
|
this.stores.setCachedMatches([...cachedMatches, ...matchesToCache]);
|
|
741
740
|
}
|
|
742
741
|
try {
|
|
@@ -771,8 +770,8 @@ var RouterCore = class {
|
|
|
771
770
|
leaveParams: true
|
|
772
771
|
};
|
|
773
772
|
const next = this.buildLocation(matchLocation);
|
|
774
|
-
if (opts?.pending && this.stores.status.
|
|
775
|
-
const baseLocation = (opts?.pending === void 0 ? !this.stores.isLoading.
|
|
773
|
+
if (opts?.pending && this.stores.status.get() !== "pending") return false;
|
|
774
|
+
const baseLocation = (opts?.pending === void 0 ? !this.stores.isLoading.get() : opts.pending) ? this.latestLocation : this.stores.resolvedLocation.get() || this.stores.location.get();
|
|
776
775
|
const match = findSingleMatch(next.pathname, opts?.caseSensitive ?? false, opts?.fuzzy ?? false, baseLocation.pathname, this.processedTree);
|
|
777
776
|
if (!match) return false;
|
|
778
777
|
if (location.params) {
|
|
@@ -782,7 +781,7 @@ var RouterCore = class {
|
|
|
782
781
|
return match.rawParams;
|
|
783
782
|
};
|
|
784
783
|
this.hasNotFoundMatch = () => {
|
|
785
|
-
return this.stores.activeMatchesSnapshot.
|
|
784
|
+
return this.stores.activeMatchesSnapshot.get().some((d) => d.status === "notFound" || d.globalNotFound);
|
|
786
785
|
};
|
|
787
786
|
this.getStoreConfig = getStoreConfig;
|
|
788
787
|
this.update({
|
|
@@ -806,7 +805,7 @@ var RouterCore = class {
|
|
|
806
805
|
return !!this.options.isPrerendering;
|
|
807
806
|
}
|
|
808
807
|
get state() {
|
|
809
|
-
return this.stores.__store.
|
|
808
|
+
return this.stores.__store.get();
|
|
810
809
|
}
|
|
811
810
|
setRoutes({ routesById, routesByPath, processedTree }) {
|
|
812
811
|
this.routesById = routesById;
|
|
@@ -834,7 +833,7 @@ var RouterCore = class {
|
|
|
834
833
|
const globalNotFoundRouteId = isGlobalNotFound ? findGlobalNotFoundRouteId(this.options.notFoundMode, matchedRoutes) : void 0;
|
|
835
834
|
const matches = new Array(matchedRoutes.length);
|
|
836
835
|
const previousActiveMatchesByRouteId = /* @__PURE__ */ new Map();
|
|
837
|
-
for (const store of this.stores.activeMatchStoresById.values()) if (store.routeId) previousActiveMatchesByRouteId.set(store.routeId, store.
|
|
836
|
+
for (const store of this.stores.activeMatchStoresById.values()) if (store.routeId) previousActiveMatchesByRouteId.set(store.routeId, store.get());
|
|
838
837
|
for (let index = 0; index < matchedRoutes.length; index++) {
|
|
839
838
|
const route = matchedRoutes[index];
|
|
840
839
|
const parentMatch = matches[index - 1];
|
|
@@ -990,8 +989,8 @@ var RouterCore = class {
|
|
|
990
989
|
for (const route of matchedRoutes) try {
|
|
991
990
|
Object.assign(accumulatedSearch, validateSearch(route.options.validateSearch, accumulatedSearch));
|
|
992
991
|
} catch {}
|
|
993
|
-
const lastStateMatchId = last(this.stores.matchesId.
|
|
994
|
-
const lastStateMatch = lastStateMatchId && this.stores.activeMatchStoresById.get(lastStateMatchId)?.
|
|
992
|
+
const lastStateMatchId = last(this.stores.matchesId.get());
|
|
993
|
+
const lastStateMatch = lastStateMatchId && this.stores.activeMatchStoresById.get(lastStateMatchId)?.get();
|
|
995
994
|
const canReuseParams = lastStateMatch && lastStateMatch.routeId === lastRoute.id && lastStateMatch.pathname === location.pathname;
|
|
996
995
|
let params;
|
|
997
996
|
if (canReuseParams) params = lastStateMatch.params;
|