Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle exceeding the localStorage quotum #65

Open
ghost opened this issue Dec 14, 2016 · 2 comments
Open

Handle exceeding the localStorage quotum #65

ghost opened this issue Dec 14, 2016 · 2 comments

Comments

@ghost
Copy link

ghost commented Dec 14, 2016

Out of curiosity, does this library handle the (unlikely) event of a user exceeding the localStorage quotum in a session? From what I understand (http://stackoverflow.com/a/14191200/5918874) in that case an exception will be thrown and no new data will be written.

Theoretically it could be possible since users can set the maximum themselves, or the device could be limited in available space.

@DiesIrae
Copy link

On last version It fails completely when quotum is exceeded.

It's a real-world problem because some browsers have no quotum (private navigation in Safari for ex.)

@DiesIrae
Copy link

For anyone having the same problem, here is my dirty solution :

import _ from "lodash"
import persistState, { mergePersistedState } from 'redux-localstorage'
import adapter from 'redux-localstorage/lib/adapters/localStorage';

const storage = window.localStorage

...

const isStorageOk = () => {
  try {
    storage.setItem("test", "1");
    storage.removeItem("test");
    return true
  }
  catch(e) {
    console.warn("No local storage", e)
  }
}

const storageAdapter = adapter(storage)

const enhancers = _.compact([
  applyMiddleware(...middlewares),
  isStorageOk() && persistState(storageAdapter, storageKey)
])

const enhancer = composeEnhancers(...enhancers)

export const store = createStore(reducer, enhancer)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant