abersager / redux-persist-cookie-storage

Redux Persist storage adapter for cookies
MIT License
92 stars 10 forks source link

Cookies don't update when state changes #21

Open Hodor9898 opened 4 years ago

Hodor9898 commented 4 years ago

When i load the application i see that the initial value of the reducer is stored in the cookies, but after i update the state it doesn't change the cookie,

App.js

export const { store, persistor } = configureStore();

const App = () => {
    return (
        <Provider store={store}>
            <PersistGate loading={null} persistor={persistor}>
                <div className="App">
                    <Router history={history}>
                        <Switch>
                            <Route path="/app" component={AppLayout}/>
                            <Route path="/" exact render={() => <Redirect push to={`${defaultRoute()}`}/>}/>
                            <Route path='*' exact={true} component={NotFoundPage}/>
                        </Switch>
                    </Router>
                </div>
                <AppSnackbar />
            </PersistGate>
        </Provider>
    );
};

store.js

const persistConfig = {
    key: 'root',
    storage: new CookieStorage(Cookies),
    whitelist: ['auth']
};

const persistedReducer = persistReducer(persistConfig, rootReducer);

export default function configureStore() {
    const middlewares = [sagaMiddleware, redirector];
    const middleWareEnhancer = applyMiddleware(...middlewares);

    const store = createStore(
        persistedReducer,
        composeWithDevTools(middleWareEnhancer)
    );

    const persistor = persistStore(store, {});

    sagaMiddleware.run(rootSaga);

    return {
        store,
        persistor
    };
}
zhaoqihao commented 4 years ago

cookie 太长了会导致不会更新

S-Cardenas commented 4 years ago

I'm seeing this same behavior. Were you able to fix it?

If there is a limit on the size of a cookie that can be stored with redux-persist, could we know what it is?

marsbergen commented 3 years ago

I'm pretty sure, this is the same issue as mentioned in #15 and since that issue is already 2 years old without any solution I think we can agree this repo is dead..

bryanltobing commented 2 years ago

@marsbergen what is the alternative for this?

dmytroboiko commented 1 year ago

I had a similar issue when I used SSR, I changed httpOnly to false on the server side and it works for me:

  const persistConfig = {
    key: "root",
    storage: new CookieStorage(cookieJar, {setCookieOptions: {httpOnly: false}}),
    stateReconciler(inboundState, originalState) {
      // Ignore state from cookies, only use preloadedState from window object
      return originalState
    }
  }