Skip to content

Redux state for costumes is being mutated #967

Open
@fsih

Description

@fsih

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

  1. Log
    console.log(this.props.stage.costumes === nextProps.stage.costumes);
    in costume-tab.jsx's componentWillReceiveProps.
  2. Add a backdrop
  3. 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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions