Skip to content

Immutability check fails in development mode #1982

@victorlin

Description

@victorlin

Current Behavior

Toggling streamtrees on → off → on causes the dev-only immutability middleware check to fail, resulting in an uncaught exception:

redux-toolkit.esm.js:467 Uncaught Error: Invariant failed: A state mutation was detected between dispatches, in the path 'tree.streams.2013 – West Africa.renderingOrder'.  This may cause incorrect behavior. (https://redux.js.org/style-guide/style-guide#do-not-mutate-state)
    at invariant (redux-toolkit.esm.js:467:9)
    at eval (redux-toolkit.esm.js:610:11)
    at Object.measureTime (redux-toolkit.esm.js:367:16)
    at eval (redux-toolkit.esm.js:606:22)
    at eval (redux-toolkit.esm.js:354:16)
    at dispatch (redux.js:627:28)
    at eval (treeStreams.ts:42:5)

at:

dispatch({type: TOGGLE_STREAM_TREE, showStreamTrees})

Redux doc: Do Not Mutate State

Expected behavior

No error.

Possible solution

I believe this is because TreeState.streams is mutated in processStreams, here and further down:

streams[sigma] = (pivots.at(-1)-pivots.at(0))/nPivots*5;

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions