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.
setUseProxies(true) but it works there ¯\_(ツ)_/¯update function) it works fine as well 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}}
The second console log should result in {id: "item-id", value: 2}}
https://codesandbox.io/s/k35j5jkj37
setUseProxies(true)setUseProxies(false) (ES5 only)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
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