diff --git a/.changeset/olive-clouds-check.md b/.changeset/olive-clouds-check.md new file mode 100644 index 0000000000..be7b921799 --- /dev/null +++ b/.changeset/olive-clouds-check.md @@ -0,0 +1,5 @@ +--- +"@tanstack/query-core": patch +--- + +fix(query-core): replaceEqualDeep max depth diff --git a/packages/query-core/src/utils.ts b/packages/query-core/src/utils.ts index 61bb09d8ba..33d023e9ca 100644 --- a/packages/query-core/src/utils.ts +++ b/packages/query-core/src/utils.ts @@ -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(a: unknown, b: T): T -export function replaceEqualDeep(a: any, b: any): any { +export function replaceEqualDeep(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))) { @@ -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++ }