rt2zz / redux-persist-immutable

Redux Persist Immutable
MIT License
114 stars 31 forks source link

[4.0.0-alpha6] autoRehydrate not working with immutable #4

Closed ntucker closed 8 years ago

ntucker commented 8 years ago

The problem is the reducer from createRehydrationReducer is only run once from the @@INIT action.

stateReconciler only matters INSIDE that reducer, but it doesn't even get the chance to run.

Maybe this is because I'm not using Action Buffers?

import { persistStore, autoRehydrate } from 'redux-persist-immutable'

  let enhancer = compose(
    autoRehydrate(),
    applyMiddleware(
      ...middleware,
    ),
  )

  const store = createStore(rootReducer, Map(), enhancer)
  persistStore(store, {
    whitelist: ['counter'],
    debounce: 500,
    storage: localforage,
  })

As mentioned: https://github.com/rt2zz/redux-persist/pull/113#issuecomment-243931005 and https://github.com/rt2zz/redux-persist/issues/165

ntucker commented 8 years ago

My redux receives this action

{type: "persist/REHYDRATE", payload: { counter: 3}, error: null}

But there is zero change in the store state.

rt2zz commented 8 years ago

You should not need action buffer for this to work. Are you using hot module reloading or webpack code splitting?

If you log inside of stateReconciler you see it execute once for the @@INIT action and not thereafter?

ntucker commented 8 years ago

I am using both hot module reloading as well as code splitting.

If you log inside of stateReconciler you see it execute once for the @@INIT action and not thereafter?

This was true before, I'll double check that it is still only happening once.

rt2zz commented 8 years ago

so this may be related to either hmr or code splitting. autorehydrate skips keys that are not found in initialState, so this may be part of the problem. One simple thing that might help us debug is to add logging to autoRehydrate: autoRehydrate({log: true})

ntucker commented 8 years ago

Hmm...strange. I nuked the node_modules and it's loading counter now.

However, now trying more complex things an encoded map is not working. I'll have to trace down if it's not saving it or not here, but it shows up as an empty map in my payload for the autorehydrate action.

...Ok, doesn't seem to be saving successive stuff. My counter is just loading at 3 each time so I guess that's why the map is empty.

ntucker commented 8 years ago

log: true doesn't seem to be adding any output to console. Is this scoped under debug, if so what wildcard should I turn on to see it?

ntucker commented 8 years ago

Turns out I had some issue with npm dependency and need to nuke even more stuff.

Out of curiosity, what does this mean:


      redux-persist/autoRehydrate: 1 actions were fired before rehydration completed. This can be a symptom of a race
      condition where the rehydrate action may overwrite the previously affected state. Consider running these actions
      after rehydration:

reconciler.js?96d7:31redux-persist/autoRehydrate: key `auth`, rehydrated to  undefined
reconciler.js?96d7:31redux-persist/autoRehydrate: key `counter`, rehydrated to  undefined

PS) Thanks for humouring me while I fixed up module setup!

rt2zz commented 8 years ago

nice!

the "1 action fired before rehydration completed" means an action fired before the REHYDRATE action, and its possible whatever state was set will have been subsequently overidden by the rehydration. In this case it may actually be the redux @@INIT action in which case there is no problem.

ntucker commented 8 years ago

Hmm, maybe you should not print message for @@INIT as that will always happen then?