localForage and getStoredState from Redux Persist
See original GitHub issueUsing getStoredState while in incognito mode or with cookies disabled in Safari causes the store to never be made available. localForage rejects it’s promise with the SecurityError thrown by Safari.
Since understanding how redux-persist and localForage interplay in this scenario and how to resolve that is too large a task for me I simply revert to not using localForage if I can get an error by trying to access localStorage like so:
let enableLocalForage = true;
try {
localStorage.setItem('__u', 'u');
}
catch (e) {
// proxy to figure out if we're in an incompatible environment for localForage
// since redux-persist doesn't play nice when localForage fails to start
enableLocalForage = false;
}
const persistConfig = {
storage: enableLocalForage ? localForage : null,
};
This stops my app from breaking when it starts but the console does get littered with warnings while in this mode.
Issue Analytics
- State:
- Created 7 years ago
- Comments:8 (6 by maintainers)
Top Results From Across the Web
redux-persist - npm
Start using redux-persist in your project by running `npm i ... If your implementatation uses getStoredState + createPersistor see alternate ...
Read more >redux-persist: How to save state on browser's local storage?
//In your createStore have this code import { applyMiddleware, compose, createStore } from 'redux' import thunkMiddleware from 'redux-thunk' ...
Read more >How to use the redux-persist.getStoredState function in ... - Snyk
To help you get started, we've selected a few redux-persist.getStoredState examples, based on popular ways it is used in public projects.
Read more >Developers - localForage and getStoredState from Redux Persist -
Using getStoredState while in incognito mode or with cookies disabled in Safari causes the store to never be made available. localForage rejects it's ......
Read more >Redux: Persisting the State to the Local Storage - Egghead.io
We will learn how to use store.subscribe() to efficiently persist some of the app's state to localStorage and restore it after a refresh....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Just wondering - looking one step back - wouldn’t localForage by itself fail when localStorage is not available and simply go to the next driver? Wouldn’t just defining memoryStorage as the fallback driver solve those issues (and still be within localForage functionality)?
PS: we could also simply extend isLocalStorageValid to actually try to call .setItem() and thus invalidate localStorage in case of Safari (or any other) errors.
update: i published https://github.com/modosc/redux-persist-memory-storage as a general purpose solution - we’ve had to use this pattern for clients with cookies or localstorage disabled.