Skip to content
Myr

fix: produce results should never be frozen when returned from nested produces, to prevent 'hiding' drafts. Fixes #935

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

authored by Michel Weststrate · committed by Michel Weststrate · parent 46867f8 · Browse files · 3 files+10 added−5 removed
This commit

State

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

Diff stats

3 files+10 added−5 removed

  • tests:+8 added−2 removed
  • other:+2 added−3 removed

3 files+10 added−5 removed

modified:__tests__/regressions.js+8 added-2 removed
250 unmodified lines
251 baz: undefined252 })253 })254255 test("Nested and chained produce calls throw 'Cannot perform 'get' on a proxy that has been revoked' error", () => {255 test.only("Nested and chained produce calls throw 'Cannot perform 'get' on a proxy that has been revoked' error", () => {256 const state = {257 foo: {258 bar: {259 baz: "banana"
6 unmodified lines
266 })267 draft.foo = produce(draft.foo, fooDraft => {268 /* another produce call makes this fail */269 /* no actual mutation necessary to make this happen */270 // This happened before becouse the outer object is not modified,271 // so assumed to be safely freezable by Immer, while it actually still272 // contains a draft of bar, which wasn't retracted since we don't do that in nested273 // producers, as it can still be modified outside a produce274 })275 })272 JSON.stringify(newState)276 expect(newState).toEqual({277 foo: {baz: "apple", bar: {baz: "banana"}}278 })279 })280 })281}
modified:src/core/finalize.ts+2 added-1 removed
modified:src/core/immerClass.ts-2 removed
86 unmodified lines
8788 // Only plain objects, arrays, and "immerable classes" are drafted.89 if (isDraftable(base)) {90 const scope = enterScope(this)91 //when base is a draft,can't freeze92 scope.canAutoFreeze_ = !isDraft(base)91 const proxy = createProxy(this, base, undefined)92 let hasError = true93 try {94 result = recipe(proxy)
147 unmodified lines