redux-persist-cookie-storage
redux-persist-cookie-storage copied to clipboard
Not persisting cookies automatically
State changes aren't being persisted unless I call persistor.persist()
.
The initial state is generated, then stored in a cookie, but any changes after that aren't being saved.
Tried with default storage and localForage and it works fine, but I need to use cookies specifically. Does anybody know what could be the cause of this issue? My config and setup seem correct according to the docs, so I am pretty sure this is a bug
I had the same issue. Probably your cookie is getting set from the server, which will prevent local cookie changes for security reasons.
I solve this by flushing the persistor and then clearing all cookies before sending the response from the server.
await persistor.flush();
res.removeHeader('Set-Cookie');
res.send($.html());
https://github.com/codejamninja/reaction-base/blob/master/src/init/server.js#L71-L73
If your cookie has the http
property checked, then it was set from the server and can't be changed locally.
I am having the exact same problem here. Was there ever a proper fix/solution?
Not that I'm aware of. Did removing the Set-Cookie
header fix it for you?
The problem was we had exceeded the maximum cookie size without realising it. Our solution was to revert back to local storage to persist redux and to sync key data from our state with a cookie
Ah nice, does it work and is it fixed?
Yeah all works perfectly :) been in production for a few months now
My issue with the cookie storage was that only one piece of my state was getting correctly persisted, while another was not. I saved this state in separate cookies, so cookie size probably doesn't apply here.
Switching back to session or local storage works perfectly fine for me.
@atbmatt sounds like you could be hitting the cookie size limit without knowing or you're using http only cookies?