Skip to content

Commit 12458ee

Browse files
TkDodomanudeli
andauthored
fix(query-core): replaceEqualDeep max depth (v4) (#10037)
* fix(query-core): replaceEqualDeep max depth * Add changeset for query-core patch --------- Co-authored-by: Jonghyeon Ko <[email protected]> Co-authored-by: Jonghyeon Ko <[email protected]>
1 parent 5b7fad4 commit 12458ee

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

.changeset/olive-clouds-check.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@tanstack/query-core": patch
3+
---
4+
5+
fix(query-core): replaceEqualDeep max depth

packages/query-core/src/utils.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -310,12 +310,14 @@ export function partialDeepEqual(a: any, b: any): boolean {
310310
* If not, it will replace any deeply equal children of `b` with those of `a`.
311311
* This can be used for structural sharing between JSON values for example.
312312
*/
313-
export function replaceEqualDeep<T>(a: unknown, b: T): T
314-
export function replaceEqualDeep(a: any, b: any): any {
313+
export function replaceEqualDeep<T>(a: unknown, b: T, depth?: number): T
314+
export function replaceEqualDeep(a: any, b: any, depth = 0): any {
315315
if (a === b) {
316316
return a
317317
}
318318

319+
if (depth > 500) return b
320+
319321
const array = isPlainArray(a) && isPlainArray(b)
320322

321323
if (array || (isPlainObject(a) && isPlainObject(b))) {
@@ -328,7 +330,7 @@ export function replaceEqualDeep(a: any, b: any): any {
328330

329331
for (let i = 0; i < bSize; i++) {
330332
const key = array ? i : bItems[i]
331-
copy[key] = replaceEqualDeep(a[key], b[key])
333+
copy[key] = replaceEqualDeep(a[key], b[key], depth + 1)
332334
if (copy[key] === a[key]) {
333335
equalItems++
334336
}

0 commit comments

Comments
 (0)