未捕获错误:在调度之间检测到状态突变

时间:2017-01-31 00:30:20

标签: javascript reactjs redux react-router-redux

我正在制作一个React + Redux应用程序,点击一个链接我就得到了这个

Uncaught Error: A state mutation was detected between dispatches, in the path `library.items.5.track.duration`. This may cause incorrect behavior. (http://redux.js.org/docs/Troubleshooting.html#never-mutate-reducer-arguments)
    at invariant (browser.js:40)
    at index.js:50
    at index.js:208
    at index.js:21
    at Object.select (bindActionCreators.js:7)
    at ListItem.handleTrackNameClick (ListItem.js:12)
    at Object.ReactErrorUtils.invokeGuardedCallback (ReactErrorUtils.js:70)
    at executeDispatch (EventPluginUtils.js:89)
    at Object.executeDispatchesInOrder (EventPluginUtils.js:112)
    at executeDispatchesAndRelease (EventPluginHub.js:44)

现在我明白这意味着,这意味着我的某些代码正在改变我的状态。我的减速器甚至没有被调用,唯一被点击的东西是:

handleTrackNameClick() {
    this.props.select([
      deepAssign({}, this.props.track)
    ]);
  }

和select函数对应于:

function playTracks(tracks) {
  console.log('playing');
  return {
    type: PLAY_TRACKS,
    tracks: deepAssign({}, tracks)
  };
}

然后(刚显示播放后)我立即得到错误,永远不会调用reducer。这很奇怪,因为我不会在我的代码中的任何地方改变我的状态。我真的不知道要发布什么,所以告诉我你是否需要更多。 Here是完整的来源

编辑:playTrack函数接收如下参数:

[
   {
      "id":"8hAt8fvQomHt9ztV",
      "name":"Bounce",
      "duration":114226,
      "artist":{
         "id":"1MUjmFoDBQOk2vbO",
         "name":"System of a Down"
      },
      "album":{
         "id":"8B7MePC7rhglf7px",
         "name":"Toxicity"
      }
   }
]

这是调用之前的示例状态:

{
   "routing":{
      "locationBeforeTransitions":{
         "pathname":"/app/library",
         "search":"",
         "hash":"",
         "state":null,
         "action":"POP",
         "key":"oabgr1",
         "query":{

         },
         "$searchBase":{
            "search":"",
            "searchBase":""
         }
      }
   },
   "toolbar":{
      "playing":false,
      "currentTime":0,
      "viewType":"redux-app/view-types/THUMBNAILS",
      "searchString":"",
      "volume":1
   },
   "library":{
      "items":[
         {
            "id":"mwgwHdOVamAz8wq0",
            "track":{
               "id":"mwgwHdOVamAz8wq0",
               "name":"A Hopeful Transmission",
               "duration":33000,
               "artist":{
                  "id":"tL1YNNTaOLvYmHot",
                  "name":"Coldplay"
               },
               "album":{
                  "id":"3xYmTho9gpG5g4bs",
                  "name":"Mylo Xyloto"
               }
            }
         },
         {
            "id":"NVcZ9spiBPSebv57",
            "track":{
               "id":"NVcZ9spiBPSebv57",
               "name":"X",
               "duration":118160,
               "artist":{
                  "id":"1MUjmFoDBQOk2vbO",
                  "name":"System of a Down"
               },
               "album":{
                  "id":"8B7MePC7rhglf7px",
                  "name":"Toxicity"
               }
            }
         },...
      ],
      "loading":false,
      "viewType":"LIST",
      "viewScope":"TRACKS"
   },
   "sidebar":{
      "libraries":[
         {
            "_id":"GaejiodsIlFRteGW",
            "name":"Test",
            "path":"/home/vinz243/.cassette/downloads"
         }
      ]
   },
   "store":{
      "query":"",
      "results":{
         "albums":[

         ],
         "tracks":[

         ]
      },
      "releases":[

      ]
   }
}

1 个答案:

答案 0 :(得分:2)

在将大块代码取消注释以试图找到它的来源之后,看来我的API返回了一些值,这些值会导致持续时间NaN值,并且乘以1000会导致此问题