redux-persist: v5 - TypeError: In this environment the sources for assign MUST be an object.This error is a performance optimization and not spec compliant

Hey, umm… i’ve tried to implement redux persist for my project… After i followed your documentation on how to implement this module, there’s no problem.

but, when i tried to reload the app…Then it shows a blank white screen and shows warning TypeError: In this environment the sources for assign MUST be an object.This error is a performance optimization and not spec compliant

Then, i tried to change the config key from root to anything… like rootzzz. And it actually works. But then when i tried to change it again to root, it shows this blank screen again, with those warning

I don’t understand what’s going on… could you help me ?

this is my reducer list ./src/reducers/index.js

import {combineReducers} from 'redux';
import { persistCombineReducers } from 'redux-persist'
import storage from 'redux-persist/es/storage';

const config = {
  key: 'root',
  storage,
}

import { reducer as formReducer } from 'redux-form'
import AuthReducer from './AuthReducer';
import SideMenuReducer from './SideMenuReducer';
import SideMenuSelectReducer from './SideMenuSelectReducer';
import HomeDashReducer from './HomeDashReducer';

const reducers = {
    form: formReducer,
    auth : AuthReducer,
    sidemenus: SideMenuReducer,
    selectedMenuId : SideMenuSelectReducer,
    menuHome : HomeDashReducer
}
export default persistCombineReducers(config, reducers);

and this is my code for ./App.js

import React, {Component} from 'react';
import {View} from 'react-native';
import expo from 'expo';
import {Provider} from 'react-redux';
import {createStore, applyMiddleware} from 'redux';
import ReduxThunk from 'redux-thunk';
import reducers from './src/reducers';
import Router from './src/Router';

import { persistStore } from 'redux-persist';
import { PersistGate } from 'redux-persist/es/integration/react';

function configureStore () {
  // ...
  let store = createStore(reducers, {}, applyMiddleware(ReduxThunk))
  let persistor = persistStore(store)

  return { persistor, store }
}

class App extends Component{

    async componentWillMount(){
        expo.Font.loadAsync({
          'Roboto_medium': require('./assets/fonts/Roboto_medium.ttf'),
        });
    }

    onBeforeLift = () => {
      // take some action before the gate lifts
    }

    render(){
        const { persistor, store } = configureStore();
        return(

            <Provider store={store}>
                <PersistGate
                    loading={<View />}
                    onBeforeLift={this.onBeforeLift}
                    persistor={persistor}
                >
                    <Router/>
              </PersistGate>

            </Provider>
        );
    }
}

export default App;

Is there anything wrong with my code ? its been 3 hours and i still have no clue

Thanks 😃

About this issue

  • Original URL
  • State: open
  • Created 7 years ago
  • Reactions: 4
  • Comments: 20 (5 by maintainers)

Most upvoted comments

I was having the same issue. This maybe is because you have a state with a root key that the value is not an object, for example:

{
  posts: [], // this is ok, is an object
  agreeToC: false // this is causing the issue because false can be deserialized
}

When trying to deserialized the above object will throw the error. Try to change to something like this

{
  posts: [], // this is ok, is an object.
  agreeToC: { accept: false } // this will fix the issue
}

If you already have a persiste store with the error:

  1. Add this line persistor.purge(); after const persistor = persistStore(store);
  2. Reload the app so the store is purged,
  3. Remove/comment the line persistor.purge();
  4. Reload the app and see if the issue is fixed

@rt2zz can you validate this comment, thanks!

actually just cut redux-persist@5.3.0-rc which hopefully resolves this. npm i redux-persist@next to test

@sun2rise I tried this line:

watchman watch-del-all && rm -rf $TMPDIR/react-* && rm -rf node_modules/ && npm cache clean && npm install && npm start -- --reset-cache

in order to reset my project but no success.

@ranggarifqi , @Cariosvertel … it all started working after a complete uninstall of the app and a new deploy with react-native run-android. Maybe the store was sill there but in a v4 fashion and everything, that’s why you need to migrate or completely reinstall the app