Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/olive-clouds-check.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@tanstack/query-core": patch
---

fix(query-core): replaceEqualDeep max depth
8 changes: 5 additions & 3 deletions packages/query-core/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,12 +310,14 @@ export function partialDeepEqual(a: any, b: any): boolean {
* If not, it will replace any deeply equal children of `b` with those of `a`.
* This can be used for structural sharing between JSON values for example.
*/
export function replaceEqualDeep<T>(a: unknown, b: T): T
export function replaceEqualDeep(a: any, b: any): any {
export function replaceEqualDeep<T>(a: unknown, b: T, depth?: number): T
export function replaceEqualDeep(a: any, b: any, depth = 0): any {
if (a === b) {
return a
}

if (depth > 500) return b

const array = isPlainArray(a) && isPlainArray(b)

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

for (let i = 0; i < bSize; i++) {
const key = array ? i : bItems[i]
copy[key] = replaceEqualDeep(a[key], b[key])
copy[key] = replaceEqualDeep(a[key], b[key], depth + 1)
if (copy[key] === a[key]) {
equalItems++
}
Expand Down