Skip to content

Commit 9d1fd29

Browse files
fix(query-core): replaceEqualDeep now handles objects with the same number of properties and one property being undefined (TanStack#6693)
this was previously fixed in router: TanStack/router#903
1 parent 91fb1eb commit 9d1fd29

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

packages/query-core/src/tests/utils.test.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,13 @@ describe('core/utils', () => {
325325
expect(result.todos[0]?.state.done).toBe(next.todos[0]?.state.done)
326326
expect(result.todos[1]).toBe(prev.todos[1])
327327
})
328+
329+
it('should correctly handle objects with the same number of properties and one property being undefined', () => {
330+
const obj1 = { a: 2, c: 123 }
331+
const obj2 = { a: 2, b: undefined }
332+
const result = replaceEqualDeep(obj1, obj2)
333+
expect(result).toStrictEqual(obj2)
334+
})
328335
})
329336

330337
describe('matchMutation', () => {

packages/query-core/src/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ export function replaceEqualDeep(a: any, b: any): any {
234234
for (let i = 0; i < bSize; i++) {
235235
const key = array ? i : bItems[i]
236236
copy[key] = replaceEqualDeep(a[key], b[key])
237-
if (copy[key] === a[key]) {
237+
if (copy[key] === a[key] && a[key] !== undefined) {
238238
equalItems++
239239
}
240240
}

0 commit comments

Comments
 (0)