Skip to content

Commit

Permalink
fix: make sure isPlainObject checks support objects send accross fram…
Browse files Browse the repository at this point in the history
…es. Fixes  #766 / #405

Co-authored-by: Yuehan Xu <[email protected]>
  • Loading branch information
atvoid and Yuehan Xu authored Mar 19, 2021
1 parent f8b77d1 commit 5ae3547
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/utils/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,20 @@ export function isDraftable(value: any): boolean {
)
}

const objectCtorString = Object.prototype.constructor.toString()
/*#__PURE__*/
export function isPlainObject(value: any): boolean {
if (!value || typeof value !== "object") return false
const proto = Object.getPrototypeOf(value)
return !proto || proto === Object.prototype
if (proto === null) {
return true
}
const Ctor =
Object.hasOwnProperty.call(proto, "constructor") && proto.constructor
return (
typeof Ctor == "function" &&
Function.toString.call(Ctor) === objectCtorString
)
}

/** Get the underlying object that is represented by the given draft */
Expand Down

0 comments on commit 5ae3547

Please sign in to comment.