Description
Expected Behavior
Redux expects that state is immutable. Mutating state breaks an assumption that redux is built on. (See an explanation here)
Actual Behavior
In scratch-gui's costume-tab.jsx
, I am comparing nextProps
against this.props
in componentWillReceiveProps
in order to try to detect when a costume is added. I noticed that this.props.stage.costumeCount
is out of sync with the actual number of costumes in this.props.stage.costumes
.
Further investigation showed that this.props.editingTarget.costumes === nextProps.editingTarget.costumes
is true. this.props was created when the number of costumes on the stage was 1, but it is now 2.
Maybe we should consider using an immutable library to ensure that states are independent.
This particular issue could be fixed by reverting #961
Steps to Reproduce
- Log
console.log(this.props.stage.costumes === nextProps.stage.costumes);
incostume-tab.jsx
'scomponentWillReceiveProps
. - Add a backdrop
- Note that since the number of backdrops just changed, the equality should be false, but it's still true.
Operating System and Browser
Windows 10 Chrome