rt2zz / redux-persist

persist and rehydrate a redux store
MIT License
12.97k stars 867 forks source link

a new bug when use redux-persist when updating app #1120

Open mvahedii opened 5 years ago

mvahedii commented 5 years ago

Hi Guys :) i'm using redux-persist for my e-commerce project. when i updated my app to new version i found a new bug. i changed my initialState from array into object. my app in Chrome (browser that i test and run my app on it) crashed !! because my initialState still array(NOT UPDATE) and new method was not returned anything.(Of course) but in Mozilla and other Browsers that i not use before them my app working currently ! why!?

My Store Config :

import { createStore, applyMiddleware } from 'redux'
import { persistStore } from 'redux-persist'
import logger from 'redux-logger'

import RootReducer from './RootReducer'

const middleware = [logger]

export const store = createStore(RootReducer, applyMiddleware(...middleware))

export const persistore = persistStore(store)

My RootReducer Config :

import { combineReducers } from 'redux'
import { persistReducer } from 'redux-persist'
import storage from 'redux-persist/lib/storage'

import UserReducer from './User/UserReducer'
import ShoppingBagDropdownReducer from './ShoppingBagDropdown/ShoppingBagDropdownReducer'
import DirectoryReducer from './Directory/DirectoryReducer'
import ShopDataReducer from './ShopData/ShopDataReducer'

const persistConfig = {
    key: 'root',
    storage,
    whileList: ['shoppingBagDropdown']
}

const rootReducer = combineReducers({
    user: UserReducer,
    shoppingBagDropdown: ShoppingBagDropdownReducer,
    shopData: ShopDataReducer,
    directory: DirectoryReducer
})

export default persistReducer(persistConfig, rootReducer)
virtualLast commented 5 years ago

I have a very similar issue, update one of the reducers in combineReducers from user to profile which is causing an error, I am going to test using stateReconciler: autoMergeLevel2 to see if that fixes the problem.

const appReducer = combineReducers({
  pushNotifications: pushNotificationReducer,
  groupCategories: groupCategoryReducer,
  conversations: conversationReducer,
  notifications: notificationReducer,
  currentGroup: currentGroupReducer,
  marketplace: marketplaceReducer,
  activity: activityReducer,
  rosettes: rosetteReducer,
  profile: profileReducer,
  general: generalReducer,
  adverts: advertReducer,
  members: memberReducer,
  errors: errorReducer,
  groups: groupReducer,
  media: mediaReducer,
});

const persistConfig = {
  key: 'root',
  storage: AsyncStorage,
  whitelist: ['general', 'activity', 'members', 'profile'], // was ['general', 'activity', 'members', 'user'] 
  stateReconciler: autoMergeLevel2,
};
mvahedii commented 5 years ago

@virtualLast First, Thanks for your answer :heart: i used createMigrate API and fixed my problem :smiley: