rt2zz / redux-persist

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

nested state disappears during persist/REHYDRATE #1285

Closed zilahir closed 3 years ago

zilahir commented 3 years ago

hey,

i am running into a problem where a piece of a state disappears during rehydrate.

I have increased the version number, and created a migration:

export const migrateStore = {
    4: state => ({
        ...state,
        layout: {
            ...state.layout,
            misc: {
                ...state.layout.misc,
                rootLevelGalleryOptions: {  // THIS IS NEW
                    ...rootLevelGalleryOptions,
                },
            },
        },
    }),
}

and then:

const persistConfig = {
    key: 'root',
    storage,
    version: 4,
    blacklist: ['temp'],
    migrate: createMigrate(migrateStore, { debug: true }),
}

the debug notifies me, that the migration has run. Then using redux-logger to observe the changes during the dispatched actoins.

action persist/REHYDRATE

in the prevState i have the object in question: state.layout.misc.rootLevelGalleryOptions.

Then when the REHYDRATE action is being callled, the key rootLevelGalleryOptions is misising from the payload, therefore it gets rehydrated this way.

Which will result with the migration not working, as I am still missing that new key from the store.

Is this a bug, or am I missing to understand something?