Skip to content

Commit

Permalink
fix(queryCache): stop deepIncludes exception comparing null (#1403)
Browse files Browse the repository at this point in the history
typeof null === 'object'

Co-authored-by: mike-shtil <mike.shtil@gmail.com>
  • Loading branch information
mike-shtil and mike-shtil committed Dec 14, 2020
1 parent 97ee733 commit 80cecef
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
24 changes: 24 additions & 0 deletions src/core/tests/utils.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,30 @@ describe('core/utils', () => {
const b = [1, 2]
expect(partialDeepEqual(a, b)).toEqual(true)
})

it('should return `false` if a is null and b is not', () => {
const a = null
const b = { a: { b: 'b' }, c: 'c', d: [{ d: 'd ' }] }
expect(partialDeepEqual(a, b)).toEqual(false)
})

it('should return `false` if a contains null and b is not', () => {
const a = { a: null, c: 'c', d: [] }
const b = { a: { b: 'b' }, c: 'c', d: [{ d: 'd ' }] }
expect(partialDeepEqual(a, b)).toEqual(false)
})

it('should return `false` if b is null and a is not', () => {
const a = { a: { b: 'b' }, c: 'c', d: [] }
const b = null
expect(partialDeepEqual(a, b)).toEqual(false)
})

it('should return `false` if b contains null and a is not', () => {
const a = { a: { b: 'b' }, c: 'c', d: [] }
const b = { a: null, c: 'c', d: [{ d: 'd ' }] }
expect(partialDeepEqual(a, b)).toEqual(false)
})
})

describe('replaceEqualDeep', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/core/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ export function partialDeepEqual(a: any, b: any): boolean {
return false
}

if (typeof a === 'object' && typeof b === 'object') {
if (a && b && typeof a === 'object' && typeof b === 'object') {
return !Object.keys(b).some(key => !partialDeepEqual(a[key], b[key]))
}

Expand Down

1 comment on commit 80cecef

@vercel
Copy link

@vercel vercel bot commented on 80cecef Dec 14, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.