From 18809a68e11c9f113b1d93c3e0c4aba15adc132b Mon Sep 17 00:00:00 2001 From: James Allen Date: Tue, 10 May 2022 12:08:23 +0100 Subject: [PATCH 1/2] Add failing test for nested and chained produce calls --- __tests__/regressions.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/__tests__/regressions.js b/__tests__/regressions.js index 329b0a09..70c0e0de 100644 --- a/__tests__/regressions.js +++ b/__tests__/regressions.js @@ -251,5 +251,25 @@ function runBaseTest(name, useProxies, autoFreeze, useListener) { baz: undefined }) }) + + test("Nested and chained produce calls throw 'Cannot perform 'get' on a proxy that has been revoked' error", () => { + const state = { + foo: { + bar: { + baz: 1 + } + } + } + const newState = produce(state, draft => { + draft.foo = produce(draft.foo, fooDraft => { + fooDraft.baz = fooDraft.bar.baz + }) + draft.foo = produce(draft.foo, fooDraft => { + /* another produce call makes this fail */ + /* no actual mutation necessary to make this happen */ + }) + }) + JSON.stringify(newState) + }) }) } From 4f77f40401173081a7ac02a98afcd491eafb1415 Mon Sep 17 00:00:00 2001 From: James Allen Date: Tue, 10 May 2022 21:03:04 +0100 Subject: [PATCH 2/2] Update test to not reference same object twice --- __tests__/regressions.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/__tests__/regressions.js b/__tests__/regressions.js index 70c0e0de..8bc587e2 100644 --- a/__tests__/regressions.js +++ b/__tests__/regressions.js @@ -256,13 +256,13 @@ function runBaseTest(name, useProxies, autoFreeze, useListener) { const state = { foo: { bar: { - baz: 1 + baz: "banana" } } } const newState = produce(state, draft => { draft.foo = produce(draft.foo, fooDraft => { - fooDraft.baz = fooDraft.bar.baz + fooDraft.baz = fooDraft.bar.baz.replace("banana", "apple") }) draft.foo = produce(draft.foo, fooDraft => { /* another produce call makes this fail */