rt2zz / redux-persist-immutable

Redux Persist Immutable
MIT License
114 stars 31 forks source link

[Solved] Arrays being rehydrated as maps #36

Closed phacks closed 6 years ago

phacks commented 6 years ago

Hi!

@gentholb & I stumbled on a tenacious problem yesterday, and after hours trying and succeeding in fixing it, we thought it would be interesting to document it here. The issue can be closed if need be.

The problem

When rehydrating, the arrays in our Redux store would be substituted by Immutable Maps.

Instead of this:

entities: [
  { index: 1 },
  { index: 2 }
]

The following structure was loaded into the store:

entities: {
  0: { index: 1 },
  1: { index: 2 }
}

This was breaking our app since we were using #Array.findIndex in our reducer, which does not work with Maps.

I had the following dependencies in my app :

"immutable": "3.8.1",
"redux-persist-immutable": "^4.3.1",
"redux-persist-transform-filter-immutable": "^0.3.0",

The solution

It turns out that the problem has been documented here and is caused by multiple Immutable versions being loaded in the app.

The https://github.com/ntucker/redux-persist-transform-filter-immutable library declares immutable@4.0.0-rc.7 as a dependency, which was causing Immutable to be loaded twice.

We then :

Hope this can help!

Thanks