Redux-persist: Problem with PersistStore whitelist

Created on 6 Sep 2017  路  20Comments  路  Source: rt2zz/redux-persist

Hi, I was trying to make only one reducer persist like in my code below:

persistStore(store, {whitelist: ['login']});

But all my reducers keep persisting,how I am suppose to make the whitelist to work? Thank you in advance!

Most helpful comment

2019, and still got this issue.... too

All 20 comments

Are you using v4 of v5?

^4.8.3

Also having this problem on 4.9.1

+1

+1 basically, right now it seems like only top level redux store keys can be treated by whitelist

@burrack that is correct, whitelist will only work on top level keys. so e.g. of the state has shape:

{
  login: loginState,
  otherThing: otherThingState,
}

adding whitelist: ['login'] will cause only login to be persisted, not otherThing

+1 the same issue is in 5.4.3

@Elena2016 what issue are you having? whitelist should work, make sure you have it applied to the persistConfig, not passed to persist store

Zack, thank you very much for your help!
persistStore(store, { storage: AsyncStorage, whitelist: ['something'] });

Errors:

  1. redux-persist: invalid option passed to persistStore: "whitelist". You may be incorrectly passing persistConfig into persistStore, whereas it should be passed into persistReducer.
  1. redux-persist: invalid option passed to persistStore: "storage". You may be incorrectly passing persistConfig into persistStore, whereas it should be passed into persistReducer.
  2. node_modules/redux-persist/lib/persistStore.js:50:38 in
  3. node_modules/redux-persist/lib/persistStore.js:49:23 in persistStore

@rt2zz - Sorry, it's my bad! I've just fixed it.
I haven't noticed that combineReducers was replaced with persistCombineReducers.

I am also having this issue:

const channelPersistConfig = {
  key: 'channel',
  storage,
  stateReconciler: autoMergeLevel1,
  blacklist: ['messages']
}

const metaPersistConfig = {
  key: 'meta',
  storage,
  stateReconciler: autoMergeLevel1,
  whitelist: ['channel']
}

const channelReducer = persistCombineReducers(channelPersistConfig, {
  messages: messagesReducer,
  meta: persistReducer(metaPersistConfig, metaReducer)})

export default channelReducer;

is my reducer, combined into my rootReducer using

const rootPersistConfig = {
  key: 'root',
  storage,
  stateReconciler: autoMergeLevel1
};

const reducers = {
  auth,
  nav: navReducer,
  channel: channelReducer
};
const rootReducer = persistCombineReducers(rootPersistConfig, reducers);

Despite the white/black list nested configs, the entire state is persisted from all reducers, as I can see by inspecting action.payload in my 'persist/REHYDRATE' state listener.

Am I using this correctly?

@dchersey - where is 'persistCombineReducers' function coming from ?

I'm following the docs in the Migration guide that say to

replace combineReducers with persistCombineReducers
e.g. let reducer = persistCombineReducers(config, reducers)

This is inconsistent with the info in the README under nested persists ... but it seemed pretty clear and I thought it would supercede it. But that is confusing ... maybe it should go back to combineReducers?

@dchersey , I am trying to do something similar with having a combination of whitelist and blacklist to cherry pick what I want to persist in redux. Have you managed to solve this? Any leads for me (and anyone who land up here).

2019, and still got this issue....
any solutions here?

2019, and still got this issue.... too

2020, and still got this issue.... too

maybe 2021 still got this issue.... too

Still an issue. Why is there no motion on this? I've tried v5 and v6 now, and no matter what combination I use of root white/blacklist keys + nested persist reducer white/blacklist keys, it's one of two outcomes:

  1. It doesn't persist the top level key at all
  2. It persists everything

I've read dozens of threads, reconfigured my persist configs and threw console dumps in the source code to inspect what's going on. It seems that the passWhitelistBlacklist function in createPersistoid is showing the correct value, but it's like it's processing the lower level keys, excluding items not in the whitelist, then seeing that the top level key passes as well and just merging in the whole top level key over top of it. If you eliminate the top level key from the root whitelist, then none of the lower level keys are persisted at all.

Here's my persist configs. I've set them up more/less exactly as the example in the docs:

export const rootPersistConfig = {
  key: 'root',
  storage: AsyncStorage,
  stateReconciler: autoMergeLevel2, // I've tried autoMergeLevel1 as well
  blacklist: ['app'],
};

const appPersistConfig = {
  key: 'app',
  storage: AsyncStorage,
  blacklist: ['collabs']
};

const rootReducer = persistCombineReducers(rootPersistConfig, {
  app: persistReducer(appPersistConfig, reducer),
});

Result when set up like example:
getStoredState

Result when I do anything I leave app out of the blacklist or keep it in the whitelist:
getStoredState-2

I've basically hit the end of the internet on this one. Can we possibly get a response on this?

I seem to be having this same issue. Anyone figure it out yet?

Please any insight on this issue? Has anyone resolved this?

Was this page helpful?
0 / 5 - 0 ratings