rt2zz / redux-persist

persist and rehydrate a redux store
MIT License
12.94k stars 866 forks source link

Usage in a chrome packaged app #143

Closed jschr closed 5 years ago

jschr commented 8 years ago

Currently redux-persist automatically sets up the default local storage backend. This causes a warning when using inside a chrome app because window.localStorage is replaced by chrome.storage.local. To workaround the warning I had to import persistStore and autoRehydrate manually. I also decided to remove the keyPrefix which isn't necessary for this storage as mentioned in https://github.com/rt2zz/redux-persist/issues/137 (let me know if thats a bad idea).

import persistStore from 'redux-persist/lib/persistStore'
import autoRehydrate from 'redux-persist/lib/autoRehydrate'
// keyprefix isnt necessary for chrome local storage and would prefer to decouple app storage from redux-persist 
require('redux-persist/lib/constants').keyPrefix = ''

...
persistStore(store, { storage: chromeLocalStorage }, () => ...)

In case this helps anyone else here is a gist of the chromeLocalStorage backend

I guess this isn't so much of an issue as fixing the warning would be a breaking change. Feel free to close or recommend a better place to post this (Wiki?)

rt2zz commented 8 years ago

@jschr thanks for digging in. This is a conundrum. Is the warning chrome gives a console.warn? I am open to breaking changes in a v4 release, but want to better understand how we can solve this without sacrificing using localStorage as a default storage backend.

I suspect we should lazily create the asyncLocalStorage backend only if a storage is not provided in the persistStore config.

jschr commented 8 years ago

Unfortunately just accessing window.localStorage will show an error in the console, app still works fine though. Lazy loading sounds like it good solution without breaking existing behaviour.

aguynamedben commented 5 years ago

This hasn't been responded to in a long while, so I'm going to mark it as stale. Please feel free to continue the conversation and I'll reopen.