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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spread in nested function call produces empty data #346

Closed
martinkadlec0 opened this issue Apr 8, 2019 · 4 comments
Closed

Spread in nested function call produces empty data #346

martinkadlec0 opened this issue Apr 8, 2019 · 4 comments

Comments

@martinkadlec0
Copy link

martinkadlec0 commented Apr 8, 2019

🐛 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)
@mweststrate
Copy link
Collaborator

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

@mweststrate
Copy link
Collaborator

mweststrate commented Apr 15, 2019

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

@martinkadlec0
Copy link
Author

fyi, it's working fine in Chrome 74.0.3729.131

@peterkrieg
Copy link

peterkrieg commented Jul 27, 2021

Curious, did anyone figure out what was up with chrome 73 to cause this? We were recently bit by this, where a user on chrome 73 had mysterious issues with data not being stored to redux correctly. Which I'm pretty sure is the same problem here with the spread returning empty data.

Either way, doesn't matter, we don't officially support that old of a version of chrome so they can upgrade, but I'm wondering if anyone dug deeper into this to see.

Like, was there an official bug report by chromium or something? That sort of thing.

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

3 participants