Skip to content

Commit 367c2c4

Browse files
committed
fix(query-core): replaceEqualDeep max depth
1 parent 44c3cb9 commit 367c2c4

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

packages/query-core/src/utils.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -264,12 +264,14 @@ const hasOwn = Object.prototype.hasOwnProperty
264264
* If not, it will replace any deeply equal children of `b` with those of `a`.
265265
* This can be used for structural sharing between JSON values for example.
266266
*/
267-
export function replaceEqualDeep<T>(a: unknown, b: T): T
268-
export function replaceEqualDeep(a: any, b: any): any {
267+
export function replaceEqualDeep<T>(a: unknown, b: T, depth?: number): T
268+
export function replaceEqualDeep(a: any, b: any, depth = 0): any {
269269
if (a === b) {
270270
return a
271271
}
272272

273+
if (depth > 500) return b
274+
273275
const array = isPlainArray(a) && isPlainArray(b)
274276

275277
if (!array && !(isPlainObject(a) && isPlainObject(b))) return b
@@ -303,7 +305,7 @@ export function replaceEqualDeep(a: any, b: any): any {
303305
continue
304306
}
305307

306-
const v = replaceEqualDeep(aItem, bItem)
308+
const v = replaceEqualDeep(aItem, bItem, depth + 1)
307309
copy[key] = v
308310
if (v === aItem) equalItems++
309311
}

0 commit comments

Comments
 (0)