redux-persist-transform-immutable icon indicating copy to clipboard operation
redux-persist-transform-immutable copied to clipboard

Uncaught Error: Error serializing unrecognized object [object Object]

Open chaintng opened this issue 9 years ago • 4 comments

UPDATE: react-boilerplate immutable is using ArrayMapNode which doesn't support toMap function That why it produce below error. Do you think it is possible to make it compatible?

I used react-boilerplate as a starter kit. It's using fromJS immutable as the store. I then try to add this library to make it persistence.

However, it have this error on my console.log

I'm not sure why does this happen, would you please advise?

image

chaintng avatar Jul 15 '16 11:07 chaintng

This project is just a wrapper around https://github.com/glenjamin/transit-immutable-js

I would say if you need ArrayNodeMap support, it would be best to file an issue there.

Also I think the situation will be improved this week when we release redux-persist-immutable with top level immutable support.

rt2zz avatar Aug 28 '16 21:08 rt2zz

Plug-an-Play support for react-boilerplate would be a delight.

luandro avatar Sep 01 '16 20:09 luandro

I could figure out how the bug occurs.

It happens here https://github.com/rt2zz/redux-persist/blob/master/src/createPersistor.js#L57: stateGetter(store.getState(), key) The default stateGetter doesn't access the immutable data structure key correctly (state[key]) so we get the wrong structure. A quick workaround for this is to pass your own getter and setter. Something like this should do the trick:

const enhancer = compose(
  applyMiddleware(...middlewares),
  autoRehydrate({
    stateReconciler(state, inboundState, reducedState){
      return state.merge(reducedState).merge(inboundState)
    },
  }),
]))

// ... other things ...

persistStore(store, {
  storage: AsyncStorage,
  transforms: [immutableTransform()],
  _stateGetter: (state, key) => state.get ? state.get(key) : state[key],
  _stateSetter: (state, key, value) => state.set ? state.set(key, value) : (state[key] = value, state),
  _stateIterator: (state, callback) => state.keySeq().forEach(key => callback(state.get(key), key)),
})

Hope that it'll be useful for anyone else there facing the same issue!

fakenickels avatar May 08 '17 19:05 fakenickels

I'm running into this issue currently, but only seeing the error in safari. Any idea why?

tdrake-cb avatar Oct 18 '17 21:10 tdrake-cb