redux-persist: Problem with SSR on v5
When state comes rehydrated from server it doesn’t gets persisted anymore on the front.
I put a console.log inside setItem of the storage I am using (redux-persist-cookie-storage) and I it never gets called
My workaround was to remove _persists before inserting state into HTML on server side.
Is this a bug or is it by design?
About this issue
- Original URL
- State: open
- Created 7 years ago
- Reactions: 1
- Comments: 17 (6 by maintainers)
Commits related to this issue
- redux-persist works for front end but not for ssr — committed to ddaaggeett/webstarter by ddaaggeett 7 years ago
@joturako I have never done SSR but I have a suspicion that if you are using redux persist cookie storage then you actualy do not want the FE to rehydrate at all. Instead you want initial redux state to be initialized with whatever the backend rehydrated from cookies.
Perhaps this is more of a question for SSR in general with redux: how does the server set initial state for redux on the client? I think if I better understood that then we could make it work with the redux-persist api. E.G. one option is to not have redux-persist rehydrate at all, but still write state updates. That would look roughly like:
just published rc.2 with this: https://github.com/rt2zz/redux-persist/blob/v5/src/persistReducer.js#L57-L58
I think that solves the problem