🐛 Bug Report
When enableArrayMethods() is added, immer does not always properly commit nested drafts, resulting in illegally accessing revoked proxies. This appears to happen when copying an existing draft object then adding it back to the array via mutation.
Link to repro
Code sandbox link
Source
import { enableArrayMethods, produce } from "immer";
enableArrayMethods();
const oldState = [{ nestedArray: [] }];
const newState = produce(oldState, (state) => {
const newVal = { ...state[0] };
state.push(newVal);
});
newState[1].nestedArray.length; // This line throws the error!
To Reproduce
- Open the above code sandbox link
- Observe error being thrown
Can also run the provided snippet in node.
Observed behavior
newState[1].nestedArray is a revoked proxy, indicating that the draft array was not committed.
This error is thrown:
TypeError: illegal operation attempted on a revoked proxy
$csb$eval index.js:16
H eval.js:31
evaluate transpiled-module.js:715
evaluateTranspiledModule manager.js:338
c transpiled-module.js:697
loadResources index.html:3
$csb$eval index.html:9
H eval.js:31
evaluate transpiled-module.js:715
evaluateTranspiledModule manager.js:338
evaluateModule manager.js:309
fi compile.ts:865
Expected behavior
All nested draft arrays are properly committed as normal arrays. This is the behavior when enableArrayMethods has not been activated.
Environment
We only accept bug reports against the latest Immer version.
🐛 Bug Report
When
enableArrayMethods()is added, immer does not always properly commit nested drafts, resulting in illegally accessing revoked proxies. This appears to happen when copying an existing draft object then adding it back to the array via mutation.Link to repro
Code sandbox link
Source
To Reproduce
Can also run the provided snippet in node.
Observed behavior
newState[1].nestedArrayis a revoked proxy, indicating that the draft array was not committed.This error is thrown:
Expected behavior
All nested draft arrays are properly committed as normal arrays. This is the behavior when
enableArrayMethodshas not been activated.Environment
We only accept bug reports against the latest Immer version.
setUseProxies(true)setUseProxies(false)(ES5 only)