diff --git a/__tests__/isDraftable.js b/__tests__/isDraftable.js new file mode 100644 index 00000000..a125d7b0 --- /dev/null +++ b/__tests__/isDraftable.js @@ -0,0 +1,7 @@ +"use strict" +import { isDraftable } from "../src/immer" + +test("non-plain object with undefined constructor doesn't error", () => { + const obj = Object.create(Object.create(null)) + expect(isDraftable(obj).toBe(true); +}) \ No newline at end of file diff --git a/src/utils/common.ts b/src/utils/common.ts index dae5064e..27a93845 100644 --- a/src/utils/common.ts +++ b/src/utils/common.ts @@ -27,7 +27,7 @@ export function isDraftable(value: any): boolean { isPlainObject(value) || Array.isArray(value) || !!value[DRAFTABLE] || - !!value.constructor[DRAFTABLE] || + !!value.constructor?.[DRAFTABLE] || isMap(value) || isSet(value) )