Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 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/happy-banks-repeat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@tanstack/query-core': patch
---

fix: use Object.is instead of === in replaceEqualDeep to correctly handle NaN equality
6 changes: 6 additions & 0 deletions packages/query-core/src/__tests__/utils.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,12 @@ describe('core/utils', () => {

expect(next).toBe(current)
})

it('should return the previous object reference when values contain NaN', () => {
const prev = { value: NaN }
const next = { value: NaN }
expect(replaceEqualDeep(prev, next)).toBe(prev)
})
})

describe('matchMutation', () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/query-core/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ const hasOwn = Object.prototype.hasOwnProperty
*/
export function replaceEqualDeep<T>(a: unknown, b: T, depth?: number): T
export function replaceEqualDeep(a: any, b: any, depth = 0): any {
if (a === b) {
if (Object.is(a, b)) {
return a
}

Expand All @@ -292,7 +292,7 @@ export function replaceEqualDeep(a: any, b: any, depth = 0): any {
const aItem = a[key]
const bItem = b[key]

if (aItem === bItem) {
if (Object.is(aItem, bItem)) {
copy[key] = aItem
if (array ? i < aSize : hasOwn.call(a, key)) equalItems++
continue
Expand Down
Loading