Skip to content

Commit

Permalink
fix: replaceDeepEqual for objects created by Object.create
Browse files Browse the repository at this point in the history
  • Loading branch information
sukovanej committed Apr 30, 2024
1 parent 38be91f commit 3afbab5
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 3afbab5

Please sign in to comment.