@tanstack/react-router 0.0.1-beta.216 → 0.0.1-beta.217
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/RouterProvider.js +13 -3
- package/build/cjs/RouterProvider.js.map +1 -1
- package/build/cjs/index.js +1 -1
- package/build/cjs/route.js.map +1 -1
- package/build/cjs/utils.js +9 -4
- package/build/cjs/utils.js.map +1 -1
- package/build/esm/index.js +22 -7
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +263 -263
- package/build/types/RouterProvider.d.ts +1 -0
- package/build/types/route.d.ts +1 -1
- package/build/types/utils.d.ts +1 -1
- package/build/umd/index.development.js +22 -7
- 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/RouterProvider.tsx +27 -7
- package/src/route.ts +10 -8
- package/src/utils.ts +12 -6
|
@@ -76,6 +76,7 @@ export interface RouteMatch<TRouteTree extends AnyRoute = AnyRoute, TRouteId ext
|
|
|
76
76
|
routeSearch: RouteById<TRouteTree, TRouteId>['types']['searchSchema'];
|
|
77
77
|
search: FullSearchSchema<TRouteTree> & RouteById<TRouteTree, TRouteId>['types']['fullSearchSchema'];
|
|
78
78
|
fetchedAt: number;
|
|
79
|
+
shouldReloadDeps: any;
|
|
79
80
|
abortController: AbortController;
|
|
80
81
|
}
|
|
81
82
|
export type AnyRouteMatch = RouteMatch<any>;
|
package/build/types/route.d.ts
CHANGED
|
@@ -34,7 +34,7 @@ export type ParamsFallback<TPath extends string, TParams> = unknown extends TPar
|
|
|
34
34
|
export type BaseRouteOptions<TParentRoute extends AnyRoute = AnyRoute, TCustomId extends string = string, TPath extends string = string, TSearchSchema extends Record<string, any> = {}, TFullSearchSchema extends Record<string, any> = TSearchSchema, TParams extends AnyPathParams = {}, TAllParams = ParamsFallback<TPath, TParams>, TRouteContext extends RouteContext = RouteContext, TAllContext extends Record<string, any> = AnyContext, TLoaderData extends any = unknown> = RoutePathOptions<TCustomId, TPath> & {
|
|
35
35
|
getParentRoute: () => TParentRoute;
|
|
36
36
|
validateSearch?: SearchSchemaValidator<TSearchSchema>;
|
|
37
|
-
shouldReload?: (match: LoaderFnContext<TAllParams, TFullSearchSchema, TAllContext, TRouteContext>) => any;
|
|
37
|
+
shouldReload?: boolean | ((match: LoaderFnContext<TAllParams, TFullSearchSchema, TAllContext, TRouteContext>) => any);
|
|
38
38
|
} & (keyof PickRequired<RouteContext> extends never ? {
|
|
39
39
|
beforeLoad?: BeforeLoadFn<TFullSearchSchema, TParentRoute, TAllParams, TRouteContext>;
|
|
40
40
|
} : {
|
package/build/types/utils.d.ts
CHANGED
|
@@ -48,7 +48,7 @@ export declare function pick<T, K extends keyof T>(parent: T, keys: K[]): Pick<T
|
|
|
48
48
|
*/
|
|
49
49
|
export declare function replaceEqualDeep<T>(prev: any, _next: T): T;
|
|
50
50
|
export declare function isPlainObject(o: any): boolean;
|
|
51
|
-
export declare function
|
|
51
|
+
export declare function deepEqual(a: any, b: any, partial?: boolean): boolean;
|
|
52
52
|
export declare function useStableCallback<T extends (...args: any[]) => any>(fn: T): T;
|
|
53
53
|
export declare function shallow<T>(objA: T, objB: T): boolean;
|
|
54
54
|
export type StrictOrFrom<TFrom> = {
|
|
@@ -558,7 +558,7 @@
|
|
|
558
558
|
function hasObjectPrototype(o) {
|
|
559
559
|
return Object.prototype.toString.call(o) === '[object Object]';
|
|
560
560
|
}
|
|
561
|
-
function
|
|
561
|
+
function deepEqual(a, b, partial = false) {
|
|
562
562
|
if (a === b) {
|
|
563
563
|
return true;
|
|
564
564
|
}
|
|
@@ -566,10 +566,15 @@
|
|
|
566
566
|
return false;
|
|
567
567
|
}
|
|
568
568
|
if (isPlainObject(a) && isPlainObject(b)) {
|
|
569
|
-
|
|
569
|
+
const aKeys = Object.keys(a);
|
|
570
|
+
const bKeys = Object.keys(b);
|
|
571
|
+
if (!partial && aKeys.length !== bKeys.length) {
|
|
572
|
+
return false;
|
|
573
|
+
}
|
|
574
|
+
return !bKeys.some(key => !(key in a) || !deepEqual(a[key], b[key], partial));
|
|
570
575
|
}
|
|
571
576
|
if (Array.isArray(a) && Array.isArray(b)) {
|
|
572
|
-
return !
|
|
577
|
+
return !a.some((item, index) => !deepEqual(item, b[index], partial));
|
|
573
578
|
}
|
|
574
579
|
return false;
|
|
575
580
|
}
|
|
@@ -1356,6 +1361,7 @@
|
|
|
1356
1361
|
loadPromise: Promise.resolve(),
|
|
1357
1362
|
context: undefined,
|
|
1358
1363
|
abortController: new AbortController(),
|
|
1364
|
+
shouldReloadDeps: undefined,
|
|
1359
1365
|
fetchedAt: 0
|
|
1360
1366
|
};
|
|
1361
1367
|
return routeMatch;
|
|
@@ -1704,7 +1710,16 @@
|
|
|
1704
1710
|
};
|
|
1705
1711
|
|
|
1706
1712
|
// Default to reloading the route all the time
|
|
1707
|
-
|
|
1713
|
+
let shouldReload = true;
|
|
1714
|
+
let shouldReloadDeps = typeof route.options.shouldReload === 'function' ? route.options.shouldReload?.(loaderContext) : !!route.options.shouldReload;
|
|
1715
|
+
if (typeof shouldReloadDeps === 'object') {
|
|
1716
|
+
// compare the deps to see if they've changed
|
|
1717
|
+
shouldReload = !deepEqual(shouldReloadDeps, match.shouldReloadDeps);
|
|
1718
|
+
console.log(shouldReloadDeps, match.shouldReloadDeps, shouldReload);
|
|
1719
|
+
match.shouldReloadDeps = shouldReloadDeps;
|
|
1720
|
+
} else {
|
|
1721
|
+
shouldReload = !!shouldReloadDeps;
|
|
1722
|
+
}
|
|
1708
1723
|
|
|
1709
1724
|
// If the user doesn't want the route to reload, just
|
|
1710
1725
|
// resolve with the existing loader data
|
|
@@ -1907,7 +1922,7 @@
|
|
|
1907
1922
|
// Combine the matches based on user options
|
|
1908
1923
|
const pathTest = activeOptions?.exact ? latestLocationRef.current.pathname === next.pathname : pathIsFuzzyEqual;
|
|
1909
1924
|
const hashTest = activeOptions?.includeHash ? latestLocationRef.current.hash === next.hash : true;
|
|
1910
|
-
const searchTest = activeOptions?.includeSearch ?? true ?
|
|
1925
|
+
const searchTest = activeOptions?.includeSearch ?? true ? deepEqual(latestLocationRef.current.search, next.search, true) : true;
|
|
1911
1926
|
|
|
1912
1927
|
// The final "active" test
|
|
1913
1928
|
const isActive = pathTest && hashTest && searchTest;
|
|
@@ -2038,7 +2053,7 @@
|
|
|
2038
2053
|
return false;
|
|
2039
2054
|
}
|
|
2040
2055
|
if (match && (opts?.includeSearch ?? true)) {
|
|
2041
|
-
return
|
|
2056
|
+
return deepEqual(baseLocation.search, next.search, true) ? match : false;
|
|
2042
2057
|
}
|
|
2043
2058
|
return match;
|
|
2044
2059
|
});
|
|
@@ -2764,6 +2779,7 @@
|
|
|
2764
2779
|
exports.createMemoryHistory = createMemoryHistory;
|
|
2765
2780
|
exports.createRouteMask = createRouteMask;
|
|
2766
2781
|
exports.decode = decode;
|
|
2782
|
+
exports.deepEqual = deepEqual;
|
|
2767
2783
|
exports.defaultParseSearch = defaultParseSearch;
|
|
2768
2784
|
exports.defaultStringifySearch = defaultStringifySearch;
|
|
2769
2785
|
exports.encode = encode;
|
|
@@ -2784,7 +2800,6 @@
|
|
|
2784
2800
|
exports.matchesContext = matchesContext;
|
|
2785
2801
|
exports.parsePathname = parsePathname;
|
|
2786
2802
|
exports.parseSearchWith = parseSearchWith;
|
|
2787
|
-
exports.partialDeepEqual = partialDeepEqual;
|
|
2788
2803
|
exports.pick = pick;
|
|
2789
2804
|
exports.redirect = redirect;
|
|
2790
2805
|
exports.replaceEqualDeep = replaceEqualDeep;
|