Skip to content

Commit

Permalink
fix(query-core): replaceEqualDeep correctly handles arrays that conta…
Browse files Browse the repository at this point in the history
…in undefined (#7376)

Co-authored-by: Dominik Dorfmeister <office@dorfmeister.cc>
  • Loading branch information
schiller-manuel and TkDodo committed May 5, 2024
1 parent 32d1e82 commit fdb0944
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
14 changes: 14 additions & 0 deletions packages/query-core/src/__tests__/utils.test.tsx
Expand Up @@ -376,6 +376,20 @@ describe('core/utils', () => {

expect(current).toBe(next)
})

it('should return the previous value when both values are an array of undefined', () => {
const current = [undefined]
const next = replaceEqualDeep(current, [undefined])

expect(next).toBe(current)
})

it('should return the previous value when both values are an array that contains undefined', () => {
const current = [{ foo: 1 }, undefined]
const next = replaceEqualDeep(current, [{ foo: 1 }, undefined])

expect(next).toBe(current)
})
})

describe('matchMutation', () => {
Expand Down
5 changes: 2 additions & 3 deletions packages/query-core/src/utils.ts
Expand Up @@ -232,10 +232,9 @@ export function replaceEqualDeep(a: any, b: any): any {
for (let i = 0; i < bSize; i++) {
const key = array ? i : bItems[i]
if (
!array &&
((!array && aItems.includes(key)) || array) &&
a[key] === undefined &&
b[key] === undefined &&
aItems.includes(key)
b[key] === undefined
) {
copy[key] = undefined
equalItems++
Expand Down

0 comments on commit fdb0944

Please sign in to comment.