redux-persist:cannot process cyclical state

Created on 29 Sep 2016  路  6Comments  路  Source: rt2zz/redux-persist

Hey,I encounter a problem like this:

      redux-persist:cannot process cyclical state.
      Consider changing your state structure to have no cycles.
      Alternatively blacklist the corresponding reducer key.
      Cycle encounted at key "context" with value "[object Object]"

And my state structure is:

    {
          "activeConversation": "223sssse234234",
          "client": IMClient, // object
          "convById": Map()   // Map, store the conversation object
          "msgById": Map()    // Map, store the message object
          convListSortedByUpdatedTimeList(), // store the message ids
    }

so how can I resolve the problem? I need your help,thank you!

Most helpful comment

I've been having basically the same issue, I'm having the log that follows:

redux-persist: cannot process cyclical state.
      Consider changing your state structure to have no cycles.
      Alternatively blacklist the corresponding reducer key.
      Cycle encounted at key "0" with value "5978ab989c24c60015f1a81c".

Where 0 is the first position of an array and 5978ab989c24c60015f1a81c is a id from my mongodb. This is being stored like this:

"data": {
     ...,
      "wallets": [
        {
          "label": String,
          "operational_settings": {
            "automatic_balance": Boolean
          },
          "user_id": userId,
          "accounts": [
            "5978ab989c24c60015f1a81c"
          ],
          "created_at": ISODate
        }
      ]
}

Any idea of what I may be doing wrong?

All 6 comments

Your state tree needs to be serializeable. That's basically the whole idea behind redux, that you can easily swap out the state tree because it is serializable. In your case it seems like you have a function inside your store.

There is a great discussion about what to put into redux's state tree here: https://github.com/reactjs/redux/issues/1385

Agree with @marvinhagemeister

Also to elaborate on the error, it means json-stringify-safe failed to serialize the state. I would check out convListSortedByUpdatedTimeList() and IMClient to make sure these do not have any circuclar data.

if you want to serialize cyclic state (and somehow have a parser that know how to do that) you can implement it via a custom transform (createTransform)

I was storing my react-navigation current navigation state in the redux store and that was somehow causing a cycle. Changed it to only store the current route name

I've been having basically the same issue, I'm having the log that follows:

redux-persist: cannot process cyclical state.
      Consider changing your state structure to have no cycles.
      Alternatively blacklist the corresponding reducer key.
      Cycle encounted at key "0" with value "5978ab989c24c60015f1a81c".

Where 0 is the first position of an array and 5978ab989c24c60015f1a81c is a id from my mongodb. This is being stored like this:

"data": {
     ...,
      "wallets": [
        {
          "label": String,
          "operational_settings": {
            "automatic_balance": Boolean
          },
          "user_id": userId,
          "accounts": [
            "5978ab989c24c60015f1a81c"
          ],
          "created_at": ISODate
        }
      ]
}

Any idea of what I may be doing wrong?

any thing new with this issue @leticiacostadias

Was this page helpful?
0 / 5 - 0 ratings

Related issues

scic picture scic  路  3Comments

elado picture elado  路  4Comments

jamesone picture jamesone  路  4Comments

benmvp picture benmvp  路  3Comments

bockc picture bockc  路  3Comments