Closed
Description
🐛 Bug Report
Starting from 8.0.2, was changed 'produce' behavior with assigning 'undefined' value. And now it looks not consistent.
Link to repro
https://runkit.com/tvolodimir/immer-undefined-behaviour
To Reproduce
// const immer = require('immer@8.0.1');
const immer = require('immer@9.0.2');
const state = {};
const newState = immer.produce(state, draft => {
draft.baz = undefined;
});
// output:
// @9.0.2: false
// @8.0.1: false
console.log(state === newState);
// output:
// @9.0.2: {}
// @8.0.1: {baz: undefined}
console.log(newState);
Observed behavior
Behavior at 8.0.1 looks normal as I am changed state from {} to {baz: undefined} and of course, it's a new object.
But at 8.0.2-9.0.2 I see no change from state {} to {} but somehow get a new object, that is cause incomprehension and also cause problems at existing code
Expected behavior
First of all how to properly handle this in 8.0.2-9.0.2.
const newState = immer.produce(state, draft => {
if (draft.baz !=== undefined) { // should I have to add checks before each assigning ?
draft.baz = undefined;
}
});
Or there are possibility to force produce to add fields with 'undefined' values?
Environment
- Immer version:
- I filed this report against the 9.0.2 version of Immer
- Occurs with
setUseProxies(true)
Activity
mweststrate commentedon Jun 9, 2021
Thanks for reporting, looks like a regression indeed!
github-actions commentedon Jul 5, 2021
🎉 This issue has been resolved in version 9.0.4 🎉
The release is available on:
Your semantic-release bot 📦🚀