Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(queryCache): stop deepIncludes exception comparing null #1403

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
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