Skip to content

Commit

Permalink
fix(core): replaceDeepEqual for objects created by Object.create (#7357)
Browse files Browse the repository at this point in the history
Co-authored-by: Dominik Dorfmeister <office@dorfmeister.cc>
  • Loading branch information
sukovanej and TkDodo committed May 4, 2024
1 parent ed12e18 commit f70d404
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
8 changes: 8 additions & 0 deletions packages/query-core/src/__tests__/utils.test.tsx
Expand Up @@ -73,6 +73,14 @@ describe('core/utils', () => {

expect(isPlainObject(Object.create(Graph))).toBeFalsy()
})

it('should return `false` for object with custom prototype', () => {
const CustomProto = Object.create({ a: 1 })
const obj = Object.create(CustomProto)
obj.b = 2

expect(isPlainObject(obj)).toBeFalsy()
})
})

describe('isPlainArray', () => {
Expand Down
5 changes: 5 additions & 0 deletions packages/query-core/src/utils.ts
Expand Up @@ -300,6 +300,11 @@ export function isPlainObject(o: any): o is Object {
return false
}

// Handles Objects created by Object.create(<arbitrary prototype>)
if (Object.getPrototypeOf(o) !== Object.prototype) {
return false
}

// Most likely a plain Object
return true
}
Expand Down

0 comments on commit f70d404

Please sign in to comment.