aohua/redux-state-sync

Error when receiving initial state, action coming as undefined when using withReduxStateSync

Closed this issue · 1 comments

Hi, Im trying to use this lib to maintain just a little bit of my application in sync, i was looking for somehing like this and o got here.
My aplication uses saga, and connected-router as middlewares, im not sure why im getting this error on the start of my application, i look in the examples, tryed not using initStateWithPrevTab, using all the methos to filter the action that i need (the action is not used or dispatched by a saga) and i cant make this work.

this is my config

const config = {
    // initiateWithState: true,
    channel: window.location.host,
    whitelist: [
        GRAVA_UNIDADE
    ],
}

this is my rootReducer

const rootReducer = history =>
  combineReducers({
    router: connectRouter(history),
    banner: bannerReducer,
    // ... All other reducers
    Intl
  });

export default withReduxStateSync(rootReducer);

this is my store creation

import rootSaga from "./rootSaga";
import rootReducer from "./rootReducer";
export const history = createBrowserHistory();
const sagaMiddleware = createSagaMiddleware();

const store = createStore(
  rootReducer(history),
  compose(
    applyMiddleware(routerMiddleware(history), sagaMiddleware, createStateSyncMiddleware(syncStateConfig)),
    //For working redux dev tools in chrome (https://github.com/zalmoxisus/redux-devtools-extension)
    window.__REDUX_DEVTOOLS_EXTENSION__
      ? window.__REDUX_DEVTOOLS_EXTENSION__({ trace: true })
      : function (f) {
        return f;
      }
  )
);

initStateWithPrevTab(store);
sagaMiddleware.run(rootSaga);

export default store;

Im not sure what I am doing wrong, if it is something with the compose (i already tryed without it), or the middlewares that im using.
If anyone can help me, I would be very grateful. Since already thank you very much.

EDIT
The problem is happening when I use withReduxStateSync on my reducers

export const createReduxStateSync = ({ prepareState }) => appReducer =>
  ((state, action) => {
    let initState = state;
    if (action.type === RECEIVE_INIT_STATE) {
      initState = prepareState(action.payload);
    }
    return appReducer(initState, action);
  });

Im still not sure why this is happening, i dont know if is something missing on my reducers, (all of them are with a standarf structure: initial state, immutable data, pure and passive). I thought that was something with using a connected router, some version, but im still with no progress on the solution

i think i solved my problem, im using connected-react-router and on my root reducer i receive history as a parameter, i was trying to use withReduxStateSync on the export of my reducer. Im still not sure exacly what was happening, but i changed my createStore, now instead of using withReduxStateSync on the export of my reducer, it is around my reducer on the createStore

const store = createStore(
  withReduxStateSync(rootReducer(history)),
  {},
  compose(...etc

Im not sure how the parameter that my reducer receive can cause that, but i will close this now that is solved.
@aohua do you think that the parameter that my reducer receive is responsable for that (i think it is, but im not sure)? If yes, do you think that sould be something to describe better on the docs? Thanks