question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

localForage and getStoredState from Redux Persist

See original GitHub issue

Using 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:open
  • Created 7 years ago
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
dvirycommented, Oct 18, 2017

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.

3reactions
modosccommented, Feb 28, 2017

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found