Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

inconsistent behavior with undefined value #807

Closed
tvolodimir opened this issue Jun 3, 2021 · 2 comments
Closed

inconsistent behavior with undefined value #807

tvolodimir opened this issue Jun 3, 2021 · 2 comments

Comments

@tvolodimir
Copy link

@tvolodimir tvolodimir commented Jun 3, 2021

馃悰 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)
@mweststrate mweststrate added the bug label Jun 9, 2021
@mweststrate
Copy link
Collaborator

@mweststrate mweststrate commented Jun 9, 2021

Thanks for reporting, looks like a regression indeed!

@github-actions
Copy link
Contributor

@github-actions github-actions bot commented Jul 5, 2021

馃帀 This issue has been resolved in version 9.0.4 馃帀

The release is available on:

Your semantic-release bot 馃摝馃殌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants