Immer: Spread in nested function call produces empty data

Created on 8 Apr 2019  ·  3Comments  ·  Source: immerjs/immer

🐛 Bug Report

When I use produce multiple times with a spread operator in a nested function call it results in an empty object instead of a shallow copy of the object.

  • I tried this in latest chrome (v73) with the umd build without babel and it still fails
  • I also tried it in latest node (v11.3) that also uses setUseProxies(true) but it works there ¯\_(ツ)_/¯
  • If you use the spread operator directly in the produce function (instead of the nested update function) it works fine as well

To Reproduce

  • Run produce multiple times - happens only on the 2nd and following calls
  • Use spread in a nested function call
    const state = {
        data: {
            'id': 'item-id',
            'value': 0,
        },
    }

    const update = (data, value) => ({...data, value})

    let newState = immer.produce(state, draftState => {
        draftState.data = update(draftState.data, 1)
    })

    console.log('1> ', newState.data) // correct: {id: "item-id", value: 1}}

    newState = immer.produce(state, draftState => {
        draftState.data = update(draftState.data, 2)
    })

    console.log('2> ', newState.data) // incorrect: {value: 2}}

Expected behavior

The second console log should result in {id: "item-id", value: 2}}

Link to repro (highly encouraged)

https://codesandbox.io/s/k35j5jkj37

Environment

  • Immer version: 2.1.5
  • [y] Occurs with setUseProxies(true)
  • [n] Occurs with setUseProxies(false) (ES5 only)
bug wontfix

Most helpful comment

I've created a minimal reproduction, the issue is unrelated to immer: https://codesandbox.io/s/94lp5j3nm4

It seems to be an issue with v8 version 7.3, However, in later versions v8 v 7.5 (chrome 75), the bug seems to be fixed. I'll try to find the original issue to cross link

All 3 comments

Weird. Fancy. Sounds like a potential V8 bug...

I've created a minimal reproduction, the issue is unrelated to immer: https://codesandbox.io/s/94lp5j3nm4

It seems to be an issue with v8 version 7.3, However, in later versions v8 v 7.5 (chrome 75), the bug seems to be fixed. I'll try to find the original issue to cross link

fyi, it's working fine in Chrome 74.0.3729.131

Was this page helpful?
0 / 5 - 0 ratings

Related issues

vidarc picture vidarc  ·  3Comments

toli444 picture toli444  ·  6Comments

DanielRuf picture DanielRuf  ·  5Comments

steida picture steida  ·  4Comments

dfadev picture dfadev  ·  6Comments