@tanstack/react-router 0.0.1-beta.281 → 0.0.1-beta.283
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/Matches.js.map +1 -1
- package/build/cjs/link.js.map +1 -1
- package/build/cjs/router.js +36 -18
- package/build/cjs/router.js.map +1 -1
- package/build/esm/index.js +36 -18
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +351 -351
- package/build/types/Matches.d.ts +1 -0
- package/build/types/link.d.ts +1 -1
- package/build/types/router.d.ts +1 -0
- package/build/umd/index.development.js +36 -18
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +2 -2
- package/src/Matches.tsx +1 -0
- package/src/link.tsx +1 -1
- package/src/router.ts +47 -27
package/build/types/Matches.d.ts
CHANGED
|
@@ -26,6 +26,7 @@ export interface RouteMatch<TRouteTree extends AnyRoute = AnyRoute, TRouteId ext
|
|
|
26
26
|
abortController: AbortController;
|
|
27
27
|
cause: 'preload' | 'enter' | 'stay';
|
|
28
28
|
loaderDeps: RouteById<TRouteTree, TRouteId>['types']['loaderDeps'];
|
|
29
|
+
preload: boolean;
|
|
29
30
|
invalid: boolean;
|
|
30
31
|
}
|
|
31
32
|
export type AnyRouteMatch = RouteMatch<any, any>;
|
package/build/types/link.d.ts
CHANGED
|
@@ -43,7 +43,7 @@ export type ToSubOptions<TRouteTree extends AnyRoute = RegisteredRouter['routeTr
|
|
|
43
43
|
state?: true | NonNullableUpdater<HistoryState>;
|
|
44
44
|
from?: TFrom;
|
|
45
45
|
} & CheckPath<TRouteTree, NoInfer<TResolved>, {}> & SearchParamOptions<TRouteTree, TFrom, TTo, TResolved> & PathParamOptions<TRouteTree, TFrom, TResolved>;
|
|
46
|
-
export type SearchParamOptions<TRouteTree extends AnyRoute, TFrom, TTo, TResolved = ResolveRelativePath<TFrom, NoInfer<TTo>>, TFromSearchEnsured = '/' extends TFrom ? FullSearchSchema<TRouteTree> : Expand<UnionToIntersection<PickRequired<RouteByPath<TRouteTree, TFrom>['types']['fullSearchSchema']>>>, TFromSearchOptional = Omit<
|
|
46
|
+
export type SearchParamOptions<TRouteTree extends AnyRoute, TFrom, TTo, TResolved = ResolveRelativePath<TFrom, NoInfer<TTo>>, TFromSearchEnsured = '/' extends TFrom ? FullSearchSchema<TRouteTree> : Expand<UnionToIntersection<PickRequired<RouteByPath<TRouteTree, TFrom>['types']['fullSearchSchema']>>>, TFromSearchOptional = Omit<FullSearchSchema<TRouteTree>, keyof TFromSearchEnsured>, TFromSearch = Expand<TFromSearchEnsured & TFromSearchOptional>, TToSearch = '' extends TTo ? FullSearchSchema<TRouteTree> : Expand<RouteByPath<TRouteTree, TResolved>['types']['fullSearchSchema']>> = keyof PickRequired<TToSearch> extends never ? {
|
|
47
47
|
search?: true | SearchReducer<TFromSearch, TToSearch>;
|
|
48
48
|
} : {
|
|
49
49
|
search: TFromSearchEnsured extends PickRequired<TToSearch> ? true | SearchReducer<TFromSearch, TToSearch> : SearchReducer<TFromSearch, TToSearch>;
|
package/build/types/router.d.ts
CHANGED
|
@@ -169,6 +169,7 @@ export declare class Router<TRouteTree extends AnyRoute = AnyRoute, TDehydrated
|
|
|
169
169
|
}) => Promise<RouteMatch[]>;
|
|
170
170
|
invalidate: () => void;
|
|
171
171
|
load: () => Promise<void>;
|
|
172
|
+
cleanCache: () => void;
|
|
172
173
|
preloadRoute: (navigateOpts?: ToOptions<TRouteTree>) => Promise<RouteMatch<AnyRoute, any>[]>;
|
|
173
174
|
matchRoute: MatchRouteFn<TRouteTree>;
|
|
174
175
|
injectHtml: (html: string | (() => Promise<string> | string)) => Promise<void>;
|
|
@@ -2327,7 +2327,8 @@
|
|
|
2327
2327
|
fetchCount: 0,
|
|
2328
2328
|
cause,
|
|
2329
2329
|
loaderDeps,
|
|
2330
|
-
invalid: false
|
|
2330
|
+
invalid: false,
|
|
2331
|
+
preload: false
|
|
2331
2332
|
};
|
|
2332
2333
|
|
|
2333
2334
|
// Regardless of whether we're reusing an existing match or creating
|
|
@@ -2740,6 +2741,10 @@
|
|
|
2740
2741
|
// Allow shouldReload to get the last say,
|
|
2741
2742
|
// if provided.
|
|
2742
2743
|
shouldReload = typeof shouldReloadOption === 'function' ? shouldReloadOption(loaderContext) : shouldReloadOption;
|
|
2744
|
+
matches[index] = match = {
|
|
2745
|
+
...match,
|
|
2746
|
+
preload: !!preload && !this.state.matches.find(d => d.id === match.id)
|
|
2747
|
+
};
|
|
2743
2748
|
if (match.status !== 'success') {
|
|
2744
2749
|
// If we need to potentially show the pending component,
|
|
2745
2750
|
// start a timer to show it after the pendingMs
|
|
@@ -2799,16 +2804,7 @@
|
|
|
2799
2804
|
let pendingMatches;
|
|
2800
2805
|
const previousMatches = this.state.matches;
|
|
2801
2806
|
this.__store.batch(() => {
|
|
2802
|
-
|
|
2803
|
-
this.__store.setState(s => {
|
|
2804
|
-
return {
|
|
2805
|
-
...s,
|
|
2806
|
-
cachedMatches: s.cachedMatches.filter(d => {
|
|
2807
|
-
const route = this.looseRoutesById[d.routeId];
|
|
2808
|
-
return d.status !== 'error' && Date.now() - d.updatedAt < (route.options.gcTime ?? this.options.defaultGcTime ?? 5 * 60 * 1000);
|
|
2809
|
-
})
|
|
2810
|
-
};
|
|
2811
|
-
});
|
|
2807
|
+
this.cleanCache();
|
|
2812
2808
|
|
|
2813
2809
|
// Match the routes
|
|
2814
2810
|
pendingMatches = this.matchRoutes(next.pathname, next.search, {
|
|
@@ -2849,13 +2845,16 @@
|
|
|
2849
2845
|
|
|
2850
2846
|
// Commit the pending matches. If a previous match was
|
|
2851
2847
|
// removed, place it in the cachedMatches
|
|
2852
|
-
this.__store.
|
|
2853
|
-
|
|
2854
|
-
|
|
2855
|
-
|
|
2856
|
-
|
|
2857
|
-
|
|
2858
|
-
|
|
2848
|
+
this.__store.batch(() => {
|
|
2849
|
+
this.__store.setState(s => ({
|
|
2850
|
+
...s,
|
|
2851
|
+
isLoading: false,
|
|
2852
|
+
matches: s.pendingMatches,
|
|
2853
|
+
pendingMatches: undefined,
|
|
2854
|
+
cachedMatches: [...s.cachedMatches, ...exitingMatches.filter(d => d.status !== 'error')]
|
|
2855
|
+
}));
|
|
2856
|
+
this.cleanCache();
|
|
2857
|
+
})
|
|
2859
2858
|
|
|
2860
2859
|
//
|
|
2861
2860
|
;
|
|
@@ -2882,6 +2881,25 @@
|
|
|
2882
2881
|
this.latestLoadPromise = promise;
|
|
2883
2882
|
return this.latestLoadPromise;
|
|
2884
2883
|
};
|
|
2884
|
+
cleanCache = () => {
|
|
2885
|
+
// This is where all of the garbage collection magic happens
|
|
2886
|
+
this.__store.setState(s => {
|
|
2887
|
+
return {
|
|
2888
|
+
...s,
|
|
2889
|
+
cachedMatches: s.cachedMatches.filter(d => {
|
|
2890
|
+
const route = this.looseRoutesById[d.routeId];
|
|
2891
|
+
if (!route.options.loader) {
|
|
2892
|
+
return false;
|
|
2893
|
+
}
|
|
2894
|
+
|
|
2895
|
+
// If the route was preloaded, use the preloadGcTime
|
|
2896
|
+
// otherwise, use the gcTime
|
|
2897
|
+
const gcTime = (d.preload ? route.options.preloadGcTime ?? this.options.defaultPreloadGcTime : route.options.gcTime ?? this.options.defaultGcTime) ?? 5 * 60 * 1000;
|
|
2898
|
+
return d.status !== 'error' && Date.now() - d.updatedAt < gcTime;
|
|
2899
|
+
})
|
|
2900
|
+
};
|
|
2901
|
+
});
|
|
2902
|
+
};
|
|
2885
2903
|
preloadRoute = async (navigateOpts = this.state.location) => {
|
|
2886
2904
|
let next = this.buildLocation(navigateOpts);
|
|
2887
2905
|
let matches = this.matchRoutes(next.pathname, next.search, {
|