@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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tanstack/react-router",
3
3
  "author": "Tanner Linsley",
4
- "version": "0.0.1-beta.216",
4
+ "version": "0.0.1-beta.217",
5
5
  "license": "MIT",
6
6
  "repository": "tanstack/router",
7
7
  "homepage": "https://tanstack.com/router",
@@ -42,7 +42,7 @@
42
42
  "@babel/runtime": "^7.16.7",
43
43
  "tiny-invariant": "^1.3.1",
44
44
  "tiny-warning": "^1.0.3",
45
- "@tanstack/history": "0.0.1-beta.216"
45
+ "@tanstack/history": "0.0.1-beta.217"
46
46
  },
47
47
  "scripts": {
48
48
  "build": "rollup --config rollup.config.js"
@@ -57,7 +57,7 @@ import {
57
57
  PickAsRequired,
58
58
  functionalUpdate,
59
59
  last,
60
- partialDeepEqual,
60
+ deepEqual,
61
61
  pick,
62
62
  replaceEqualDeep,
63
63
  useStableCallback,
@@ -492,6 +492,7 @@ export function RouterProvider<
492
492
  loadPromise: Promise.resolve(),
493
493
  context: undefined!,
494
494
  abortController: new AbortController(),
495
+ shouldReloadDeps: undefined,
495
496
  fetchedAt: 0,
496
497
  }
497
498
 
@@ -984,8 +985,28 @@ export function RouterProvider<
984
985
  }
985
986
 
986
987
  // Default to reloading the route all the time
987
- const shouldReload =
988
- route.options.shouldReload?.(loaderContext) ?? true
988
+ let shouldReload = true
989
+ let shouldReloadDeps =
990
+ typeof route.options.shouldReload === 'function'
991
+ ? route.options.shouldReload?.(loaderContext)
992
+ : !!route.options.shouldReload
993
+
994
+ if (typeof shouldReloadDeps === 'object') {
995
+ // compare the deps to see if they've changed
996
+ shouldReload = !deepEqual(
997
+ shouldReloadDeps,
998
+ match.shouldReloadDeps,
999
+ )
1000
+ console.log(
1001
+ shouldReloadDeps,
1002
+ match.shouldReloadDeps,
1003
+ shouldReload,
1004
+ )
1005
+
1006
+ match.shouldReloadDeps = shouldReloadDeps
1007
+ } else {
1008
+ shouldReload = !!shouldReloadDeps
1009
+ }
989
1010
 
990
1011
  // If the user doesn't want the route to reload, just
991
1012
  // resolve with the existing loader data
@@ -1251,7 +1272,7 @@ export function RouterProvider<
1251
1272
  : true
1252
1273
  const searchTest =
1253
1274
  activeOptions?.includeSearch ?? true
1254
- ? partialDeepEqual(latestLocationRef.current.search, next.search)
1275
+ ? deepEqual(latestLocationRef.current.search, next.search, true)
1255
1276
  : true
1256
1277
 
1257
1278
  // The final "active" test
@@ -1406,9 +1427,7 @@ export function RouterProvider<
1406
1427
  }
1407
1428
 
1408
1429
  if (match && (opts?.includeSearch ?? true)) {
1409
- return partialDeepEqual(baseLocation.search, next.search)
1410
- ? match
1411
- : false
1430
+ return deepEqual(baseLocation.search, next.search, true) ? match : false
1412
1431
  }
1413
1432
 
1414
1433
  return match
@@ -1493,6 +1512,7 @@ export interface RouteMatch<
1493
1512
  search: FullSearchSchema<TRouteTree> &
1494
1513
  RouteById<TRouteTree, TRouteId>['types']['fullSearchSchema']
1495
1514
  fetchedAt: number
1515
+ shouldReloadDeps: any
1496
1516
  abortController: AbortController
1497
1517
  }
1498
1518
 
package/src/route.ts CHANGED
@@ -108,14 +108,16 @@ export type BaseRouteOptions<
108
108
  > = RoutePathOptions<TCustomId, TPath> & {
109
109
  getParentRoute: () => TParentRoute
110
110
  validateSearch?: SearchSchemaValidator<TSearchSchema>
111
- shouldReload?: (
112
- match: LoaderFnContext<
113
- TAllParams,
114
- TFullSearchSchema,
115
- TAllContext,
116
- TRouteContext
117
- >,
118
- ) => any
111
+ shouldReload?:
112
+ | boolean
113
+ | ((
114
+ match: LoaderFnContext<
115
+ TAllParams,
116
+ TFullSearchSchema,
117
+ TAllContext,
118
+ TRouteContext
119
+ >,
120
+ ) => any)
119
121
  } & (keyof PickRequired<RouteContext> extends never
120
122
  ? // This async function is called before a route is loaded.
121
123
  // If an error is thrown here, the route's loader will not be called.
package/src/utils.ts CHANGED
@@ -231,7 +231,7 @@ function hasObjectPrototype(o: any) {
231
231
  return Object.prototype.toString.call(o) === '[object Object]'
232
232
  }
233
233
 
234
- export function partialDeepEqual(a: any, b: any): boolean {
234
+ export function deepEqual(a: any, b: any, partial: boolean = false): boolean {
235
235
  if (a === b) {
236
236
  return true
237
237
  }
@@ -241,14 +241,20 @@ export function partialDeepEqual(a: any, b: any): boolean {
241
241
  }
242
242
 
243
243
  if (isPlainObject(a) && isPlainObject(b)) {
244
- return !Object.keys(b).some((key) => !partialDeepEqual(a[key], b[key]))
244
+ const aKeys = Object.keys(a)
245
+ const bKeys = Object.keys(b)
246
+
247
+ if (!partial && aKeys.length !== bKeys.length) {
248
+ return false
249
+ }
250
+
251
+ return !bKeys.some(
252
+ (key) => !(key in a) || !deepEqual(a[key], b[key], partial),
253
+ )
245
254
  }
246
255
 
247
256
  if (Array.isArray(a) && Array.isArray(b)) {
248
- return !(
249
- a.length !== b.length ||
250
- a.some((item, index) => !partialDeepEqual(item, b[index]))
251
- )
257
+ return !a.some((item, index) => !deepEqual(item, b[index], partial))
252
258
  }
253
259
 
254
260
  return false