@tanstack/query-core 5.85.6 → 5.85.7

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.
Files changed (78) hide show
  1. package/build/legacy/{hydration-DTop62kY.d.cts → hydration-BC7iBQD-.d.cts} +2 -2
  2. package/build/legacy/{hydration-Dh_94ejg.d.ts → hydration-BpLOP9Dw.d.ts} +2 -2
  3. package/build/legacy/hydration.d.cts +1 -1
  4. package/build/legacy/hydration.d.ts +1 -1
  5. package/build/legacy/index.d.cts +1 -1
  6. package/build/legacy/index.d.ts +1 -1
  7. package/build/legacy/infiniteQueryBehavior.d.cts +1 -1
  8. package/build/legacy/infiniteQueryBehavior.d.ts +1 -1
  9. package/build/legacy/infiniteQueryObserver.d.cts +1 -1
  10. package/build/legacy/infiniteQueryObserver.d.ts +1 -1
  11. package/build/legacy/mutation.d.cts +1 -1
  12. package/build/legacy/mutation.d.ts +1 -1
  13. package/build/legacy/mutationCache.d.cts +1 -1
  14. package/build/legacy/mutationCache.d.ts +1 -1
  15. package/build/legacy/mutationObserver.d.cts +1 -1
  16. package/build/legacy/mutationObserver.d.ts +1 -1
  17. package/build/legacy/queriesObserver.d.cts +1 -1
  18. package/build/legacy/queriesObserver.d.ts +1 -1
  19. package/build/legacy/query.d.cts +1 -1
  20. package/build/legacy/query.d.ts +1 -1
  21. package/build/legacy/queryCache.d.cts +1 -1
  22. package/build/legacy/queryCache.d.ts +1 -1
  23. package/build/legacy/queryClient.d.cts +1 -1
  24. package/build/legacy/queryClient.d.ts +1 -1
  25. package/build/legacy/queryObserver.d.cts +1 -1
  26. package/build/legacy/queryObserver.d.ts +1 -1
  27. package/build/legacy/retryer.d.cts +1 -1
  28. package/build/legacy/retryer.d.ts +1 -1
  29. package/build/legacy/streamedQuery.d.cts +1 -1
  30. package/build/legacy/streamedQuery.d.ts +1 -1
  31. package/build/legacy/types.d.cts +1 -1
  32. package/build/legacy/types.d.ts +1 -1
  33. package/build/legacy/utils.cjs +24 -21
  34. package/build/legacy/utils.cjs.map +1 -1
  35. package/build/legacy/utils.d.cts +1 -1
  36. package/build/legacy/utils.d.ts +1 -1
  37. package/build/legacy/utils.js +24 -21
  38. package/build/legacy/utils.js.map +1 -1
  39. package/build/modern/{hydration-DTop62kY.d.cts → hydration-BC7iBQD-.d.cts} +2 -2
  40. package/build/modern/{hydration-Dh_94ejg.d.ts → hydration-BpLOP9Dw.d.ts} +2 -2
  41. package/build/modern/hydration.d.cts +1 -1
  42. package/build/modern/hydration.d.ts +1 -1
  43. package/build/modern/index.d.cts +1 -1
  44. package/build/modern/index.d.ts +1 -1
  45. package/build/modern/infiniteQueryBehavior.d.cts +1 -1
  46. package/build/modern/infiniteQueryBehavior.d.ts +1 -1
  47. package/build/modern/infiniteQueryObserver.d.cts +1 -1
  48. package/build/modern/infiniteQueryObserver.d.ts +1 -1
  49. package/build/modern/mutation.d.cts +1 -1
  50. package/build/modern/mutation.d.ts +1 -1
  51. package/build/modern/mutationCache.d.cts +1 -1
  52. package/build/modern/mutationCache.d.ts +1 -1
  53. package/build/modern/mutationObserver.d.cts +1 -1
  54. package/build/modern/mutationObserver.d.ts +1 -1
  55. package/build/modern/queriesObserver.d.cts +1 -1
  56. package/build/modern/queriesObserver.d.ts +1 -1
  57. package/build/modern/query.d.cts +1 -1
  58. package/build/modern/query.d.ts +1 -1
  59. package/build/modern/queryCache.d.cts +1 -1
  60. package/build/modern/queryCache.d.ts +1 -1
  61. package/build/modern/queryClient.d.cts +1 -1
  62. package/build/modern/queryClient.d.ts +1 -1
  63. package/build/modern/queryObserver.d.cts +1 -1
  64. package/build/modern/queryObserver.d.ts +1 -1
  65. package/build/modern/retryer.d.cts +1 -1
  66. package/build/modern/retryer.d.ts +1 -1
  67. package/build/modern/streamedQuery.d.cts +1 -1
  68. package/build/modern/streamedQuery.d.ts +1 -1
  69. package/build/modern/types.d.cts +1 -1
  70. package/build/modern/types.d.ts +1 -1
  71. package/build/modern/utils.cjs +24 -21
  72. package/build/modern/utils.cjs.map +1 -1
  73. package/build/modern/utils.d.cts +1 -1
  74. package/build/modern/utils.d.ts +1 -1
  75. package/build/modern/utils.js +24 -21
  76. package/build/modern/utils.js.map +1 -1
  77. package/package.json +1 -1
  78. package/src/utils.ts +37 -30
package/src/utils.ts CHANGED
@@ -245,6 +245,8 @@ export function partialMatchKey(a: any, b: any): boolean {
245
245
  return false
246
246
  }
247
247
 
248
+ const hasOwn = Object.prototype.hasOwnProperty
249
+
248
250
  /**
249
251
  * This function returns `a` if `b` is deeply equal.
250
252
  * If not, it will replace any deeply equal children of `b` with those of `a`.
@@ -258,37 +260,43 @@ export function replaceEqualDeep(a: any, b: any): any {
258
260
 
259
261
  const array = isPlainArray(a) && isPlainArray(b)
260
262
 
261
- if (array || (isPlainObject(a) && isPlainObject(b))) {
262
- const aItems = array ? a : Object.keys(a)
263
- const aSize = aItems.length
264
- const bItems = array ? b : Object.keys(b)
265
- const bSize = bItems.length
266
- const copy: any = array ? [] : {}
267
- const aItemsSet = new Set(aItems)
268
-
269
- let equalItems = 0
270
-
271
- for (let i = 0; i < bSize; i++) {
272
- const key = array ? i : bItems[i]
273
- if (
274
- ((!array && aItemsSet.has(key)) || array) &&
275
- a[key] === undefined &&
276
- b[key] === undefined
277
- ) {
278
- copy[key] = undefined
279
- equalItems++
280
- } else {
281
- copy[key] = replaceEqualDeep(a[key], b[key])
282
- if (copy[key] === a[key] && a[key] !== undefined) {
283
- equalItems++
284
- }
285
- }
263
+ if (!array && !(isPlainObject(a) && isPlainObject(b))) return b
264
+
265
+ const aItems = array ? a : Object.keys(a)
266
+ const aSize = aItems.length
267
+ const bItems = array ? b : Object.keys(b)
268
+ const bSize = bItems.length
269
+ const copy: any = array ? new Array(bSize) : {}
270
+
271
+ let equalItems = 0
272
+
273
+ for (let i = 0; i < bSize; i++) {
274
+ const key: any = array ? i : bItems[i]
275
+ const aItem = a[key]
276
+ const bItem = b[key]
277
+
278
+ if (aItem === bItem) {
279
+ copy[key] = aItem
280
+ if (array ? i < aSize : hasOwn.call(a, key)) equalItems++
281
+ continue
282
+ }
283
+
284
+ if (
285
+ aItem === null ||
286
+ bItem === null ||
287
+ typeof aItem !== 'object' ||
288
+ typeof bItem !== 'object'
289
+ ) {
290
+ copy[key] = bItem
291
+ continue
286
292
  }
287
293
 
288
- return aSize === bSize && equalItems === aSize ? a : copy
294
+ const v = replaceEqualDeep(aItem, bItem)
295
+ copy[key] = v
296
+ if (v === aItem) equalItems++
289
297
  }
290
298
 
291
- return b
299
+ return aSize === bSize && equalItems === aSize ? a : copy
292
300
  }
293
301
 
294
302
  /**
@@ -311,13 +319,12 @@ export function shallowEqualObjects<T extends Record<string, any>>(
311
319
  return true
312
320
  }
313
321
 
314
- export function isPlainArray(value: unknown) {
322
+ export function isPlainArray(value: unknown): value is Array<unknown> {
315
323
  return Array.isArray(value) && value.length === Object.keys(value).length
316
324
  }
317
325
 
318
326
  // Copied from: https://github.com/jonschlinkert/is-plain-object
319
- // eslint-disable-next-line @typescript-eslint/no-wrapper-object-types
320
- export function isPlainObject(o: any): o is Object {
327
+ export function isPlainObject(o: any): o is Record<PropertyKey, unknown> {
321
328
  if (!hasObjectPrototype(o)) {
322
329
  return false
323
330
  }