You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It seems that iterating over Immer's draft of a Set can cause mutations to be ignored. This seems to only happen when you iterate over the set before performing any mutations.
const{produce, enableMapSet}=require("immer");const{expect}=require("chai");enableMapSet();letset=newSet([1,2]);expect(Array.from(set).sort()).to.eql([1,2]);// If we just add to the set, it works!set=produce(set,draftSet=>{draftSet.add(3);});expect(Array.from(set).sort()).to.eql([1,2,3]);// And we can safely iterate over the set between changes,// and changes before and after will be applied correctly.set=produce(set,draftSet=>{draftSet.add(4);console.log("By the way, the set is ",Array.from(draftSet));draftSet.add(5);});expect(Array.from(set).sort()).to.eql([1,2,3,4,5]);// But if we iterate over the set *before* making any changes,// then all of our changes are ignored.//// This test case fails in Immer 6.0.3.set=produce(set,draftSet=>{console.log("By the way, the set is ",Array.from(draftSet));draftSet.add(6);});expect(Array.from(set).sort()).to.eql([1,2,3,4,5,6]);console.log("Done!");
To Reproduce
Enable Immer's MapSet plugin.
Use a produce function over the Set, which iterates over the content of the draft set and then mutates it.
Observed behavior
Mutations made to the draft Set during produce are not reflected in its return value.
Expected behavior
Mutations made to the draft Set during produce would be reflected in its return value, just as if I had not performed iteration before attempting mutation.
Environment
Immer version: 6.0.3
Occurs with setUseProxies(true)
Occurs with setUseProxies(false) (ES5 only)
The text was updated successfully, but these errors were encountered:
馃悰 Bug Report
It seems that iterating over Immer's draft of a
Set
can cause mutations to be ignored. This seems to only happen when you iterate over the set before performing any mutations.Link to repro
Here's a runnable code sample: https://runkit.com/matchu/5ea3a4b828ff10001bb538ea
To Reproduce
MapSet
plugin.produce
function over theSet
, which iterates over the content of the draft set and then mutates it.Observed behavior
Mutations made to the draft
Set
duringproduce
are not reflected in its return value.Expected behavior
Mutations made to the draft
Set
duringproduce
would be reflected in its return value, just as if I had not performed iteration before attempting mutation.Environment
setUseProxies(true)
setUseProxies(false)
(ES5 only)The text was updated successfully, but these errors were encountered: