-
-
Notifications
You must be signed in to change notification settings - Fork 851
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Nested and chained produce usage results in error: Cannot perform 'get' on a proxy that has been revoked #936
Comments
Your test creates a non-unidirectional graph, which isn't supported by Immer. There should be only one single path from any node in your tree to the root. After the first assignment, |
Thanks for the reply! In the real situation where I've encountered this issue, I'm not setting another direct reference to The failing test is then: const state = {
foo: {
bar: {
baz: "banana"
}
}
}
const newState = produce(state, draft => {
draft.foo = produce(draft.foo, fooDraft => {
fooDraft.baz = fooDraft.bar.baz.replace("banana", "apple")
})
draft.foo = produce(draft.foo, fooDraft => {
/* another produce call makes this fail */
/* no actual mutation necessary to make this happen */
})
})
JSON.stringify(newState) I would expect {
foo: {
bar: {
baz: "banana"
},
baz: "apple"
}
} |
This comment was marked as spam.
This comment was marked as spam.
Same thing happens with let state = createDraft({})
state.x = 10
let patches, inversePatches, nextState
nextState = finishDraft(state, (p, ip) => {
patches = p
inversePatches = ip
})
state = createDraft(nextState)
state.x = 20
// Throws
// TypeError: Cannot perform 'get' on a proxy that has been revoked
// as nextState is frozen by `setAutoFreeze` Edit: The problem is not directly visible in that code, but trying to integrate this into a reactive store, we need keep snapshots or a pointer to the previous state. Is there a workaround to keep a pointer to |
Closing as original issue seems solved |
🐛 Bug Report
When using nested and chained
produce
calls, when a property is copied from a child object to the parent, immer throws an error when accessing the property in the final state:Link to repro
PR with failing unit test is in #935
To Reproduce
The following example code shows this error:
Observed behavior
An error is throw while reading the modified property
Expected behavior
No error to be throw.
Environment
Only seems to happen with
autoFreeze = true
.setUseProxies(true)
setUseProxies(false)
(ES5 only)The text was updated successfully, but these errors were encountered: