Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught Error: Error serializing unrecognized object [object Object] #13

Open
chaintng opened this issue Jul 15, 2016 · 4 comments
Open

Comments

@chaintng
Copy link
Contributor

chaintng commented Jul 15, 2016

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

@rt2zz
Copy link
Owner

rt2zz commented Aug 28, 2016

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.

@luandro
Copy link

luandro commented Sep 1, 2016

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

@fakenickels
Copy link

fakenickels commented May 8, 2017

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!

@tdrake-cb
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants