Skip to content

inconsistent behavior with undefined value #807

Closed
@tvolodimir

Description

@tvolodimir

🐛 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

mweststrate commented on Jun 9, 2021

@mweststrate
Collaborator

Thanks for reporting, looks like a regression indeed!

github-actions

github-actions commented on Jul 5, 2021

@github-actions
Contributor

🎉 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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @tvolodimir@mweststrate

        Issue actions

          inconsistent behavior with undefined value · Issue #807 · immerjs/immer