@tanstack/react-router 0.0.1-beta.216 → 0.0.1-beta.218

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.
@@ -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>;
@@ -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
  } : {
@@ -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 partialDeepEqual(a: any, b: any): boolean;
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 partialDeepEqual(a, b) {
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
- return !Object.keys(b).some(key => !partialDeepEqual(a[key], b[key]));
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 !(a.length !== b.length || a.some((item, index) => !partialDeepEqual(item, b[index])));
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
- const shouldReload = route.options.shouldReload?.(loaderContext) ?? true;
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 ? partialDeepEqual(latestLocationRef.current.search, next.search) : 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 partialDeepEqual(baseLocation.search, next.search) ? match : false;
2056
+ return deepEqual(baseLocation.search, next.search, true) ? match : false;
2042
2057
  }
2043
2058
  return match;
2044
2059
  });
@@ -2126,7 +2141,7 @@
2126
2141
  const PendingComponent = route.options.pendingComponent ?? options.defaultPendingComponent ?? defaultPending;
2127
2142
  const routeErrorComponent = route.options.errorComponent ?? options.defaultErrorComponent ?? ErrorComponent;
2128
2143
  const ResolvedSuspenseBoundary = route.options.wrapInSuspense ? React__namespace.Suspense : SafeFragment;
2129
- const errorComponent = React__namespace.useCallback(props => {
2144
+ const errorComponent = routeErrorComponent ? React__namespace.useCallback(props => {
2130
2145
  return /*#__PURE__*/React__namespace.createElement(routeErrorComponent, {
2131
2146
  ...props,
2132
2147
  useMatch: route.useMatch,
@@ -2134,7 +2149,7 @@
2134
2149
  useSearch: route.useSearch,
2135
2150
  useParams: route.useParams
2136
2151
  });
2137
- }, [route]);
2152
+ }, [route]) : undefined;
2138
2153
  return /*#__PURE__*/React__namespace.createElement(matchesContext.Provider, {
2139
2154
  value: matches
2140
2155
  }, /*#__PURE__*/React__namespace.createElement(ResolvedSuspenseBoundary, {
@@ -2144,7 +2159,7 @@
2144
2159
  useSearch: route.useSearch,
2145
2160
  useParams: route.useParams
2146
2161
  })
2147
- }, /*#__PURE__*/React__namespace.createElement(CatchBoundary, {
2162
+ }, errorComponent ? /*#__PURE__*/React__namespace.createElement(CatchBoundary, {
2148
2163
  resetKey: locationKey,
2149
2164
  errorComponent: errorComponent,
2150
2165
  onCatch: () => {
@@ -2152,6 +2167,8 @@
2152
2167
  }
2153
2168
  }, /*#__PURE__*/React__namespace.createElement(MatchInner, {
2154
2169
  match: match
2170
+ })) : /*#__PURE__*/React__namespace.createElement(SafeFragment, null, /*#__PURE__*/React__namespace.createElement(MatchInner, {
2171
+ match: match
2155
2172
  }))));
2156
2173
  }
2157
2174
  function MatchInner({
@@ -2764,6 +2781,7 @@
2764
2781
  exports.createMemoryHistory = createMemoryHistory;
2765
2782
  exports.createRouteMask = createRouteMask;
2766
2783
  exports.decode = decode;
2784
+ exports.deepEqual = deepEqual;
2767
2785
  exports.defaultParseSearch = defaultParseSearch;
2768
2786
  exports.defaultStringifySearch = defaultStringifySearch;
2769
2787
  exports.encode = encode;
@@ -2784,7 +2802,6 @@
2784
2802
  exports.matchesContext = matchesContext;
2785
2803
  exports.parsePathname = parsePathname;
2786
2804
  exports.parseSearchWith = parseSearchWith;
2787
- exports.partialDeepEqual = partialDeepEqual;
2788
2805
  exports.pick = pick;
2789
2806
  exports.redirect = redirect;
2790
2807
  exports.replaceEqualDeep = replaceEqualDeep;