Skip to content
Myr

Merge pull request #1193 from immerjs/bugfix/1192-non-draftable-values

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Re-add isDraftable check to skip freezing non-obj values

authored by Mark Erikson · committed by GitHub · parents d6c1202, ad510d4 · Browse files · 2 files+24 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+24 added−1 removed

  • tests:+23 added−0 removed
  • other:+1 added−1 removed

2 files+24 added−1 removed

modified:__tests__/base.js+23 added
2675 unmodified lines
2676 ) // should throw!2677 })26782679 autoFreeze &&2680 test("issue #1190 / #1192 - should not freeze non-draftable objects (class instances and typed arrays)", () => {2681 class MutableClass {2682 value = 52683 }26842685 const state = {2686 someValue: 5,2687 mutableClass: new MutableClass(),2688 typedArray: new Uint8Array(10)2689 }26902691 expect(() => {2692 // Should not throw when producing with autoFreeze enabled2693 const result = produce(state, draft => {2694 draft.someValue = 62695 })26962697 // Verify the non-draftable class instance is not frozen2698 state.mutableClass.value = 62699 }).not.toThrow()2700 })27012702 autoFreeze &&2703 test("issue #469, state not frozen", () => {2704 const project = produce(2705 {2706 id: 1,
842 unmodified lines
modified:src/utils/common.ts+1 added-1 removed
241 unmodified lines
242 * @param deep243 */244export function freeze<T>(obj: T, deep?: boolean): T245export function freeze<T>(obj: any, deep: boolean = false): T {246 if (isFrozen(obj) || isDraft(obj)) return obj246 if (isFrozen(obj) || isDraft(obj) || !isDraftable(obj)) return obj247 if (getArchtype(obj) > 1 /* Map or Set */) {248 O.defineProperties(obj, {249 set: dontMutateMethodOverride,250 add: dontMutateMethodOverride,
31 unmodified lines