Closed relsunkaev closed 1 year ago
@relsunkaev Mutative just drafts the baseState. I'm not sure how you're using it, but one thing is certain: the draft tree should not be used directly in any external function. You may encounter draft escaping, for example:
let a: any;
const state = create({ a: { b: 1 } }, (draft) => {
draft.a.b = 2;
a = draft.a;
});
// Don't use 'a', 'a' is a draft.
expect(() => {
JSON.stringify(a);
}).toThrowError(`Cannot perform 'get' on a proxy that has been revoked`);
// state.a is a object, not a draft
It would be helpful if you could provide a minimal example to help identify and troubleshoot the issue.
Yeah that was exactly what I was doing wrong. Closing the issue.
I have a use case where I access the
base
state in anonSuccess
callback of a mutation. Something along the lines ofHowever, it seems like base is a proxy object that gets revoked at some point between the call to
mutation.mutate()
and the call toonSuccess()
. Currently I'm copying the base into a separate object before every mutation like thisbut that is not ideal.
Is mutative actually passing a proxy object as
base
? If so, is this addressable on your end and/or are there any other workarounds I could use?Note: this issue does not occur if running React in Strict Mode.