-
Notifications
You must be signed in to change notification settings - Fork 866
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can I upgrade to v5 on an existing app using v4 and keep my data? #434
Comments
Just checked the storage now, I see the keys are different, everything is under the root key, so is there a easy way to migrate data from v4? or should I just keep on v4? |
there is not currently a way to migrate state from v4 to v5. I think the way to solve this would be for redux-persist to ship with a pluggable "getStoredState": import { getStoredState } from 'redux-persist'
import { getStoredStateV4 } from 'redux-persist/lib/integration'
const v4Config = { /* whatever the old config was */ }
const config = {
key,
storage,
getStoredState: async (persistConfig) => {
let storedState = getStoredState(persistConfig)
if (!storedState) storedState = getStoredStateV4(v4Config)
return storedState
}
}
persistReducer(config, baseReducer) Its not the prettiest api, but the pattern would be generally useful, could be used to move from one storage engine to another for example. NOTE this is not currently possible, we would need to add |
I dont know how the internals work, is it easy to do? do you plan to implement it? |
the implementation would be trivial, I just would want to take some time first to make sure this is the right api. In abstract I would like to call the config option: "migrate" or something, but unfortunately "migrate" is a loaded word, we already use that for migrating state between app state versions. |
I just took a first stab at it: https://github.com/rt2zz/redux-persist/tree/v5#experimental-v4-to-v5-state-migration I have not run this code at all so it likely requires some tweaking, but it should be generally a good approach. |
@rt2zz I'm trying to migrate from v4 to v5 using the experimental migration. It works fine for extracting the data, but if I try and add a migration at the same time it errors because Update |
Hi folks, can I revive this issue by asking if there is any update on how to migrate? Because it looks like the migration guide that was present in the README and linked by @rt2zz earlier is now 404 😅 |
@levsero Did you get end up getting this working? Thanks for taking the time to submit that fix. I'm going to try the experimental feature in the next few days, after I implement the upgrade from v4 to v5. FWIW my situation: I built a new feature assuming I could run async code during a redux migration, but redux-persist-migrate v4.x doesn't support async code in migrations. redux-persist v5 has first-class support for migrations and allows a Promise to be returned to run a migration (👍!!!). But the pain level of clearing local state is very high, as my users invest a lot in configuration that is stored locally for a good reason. @rt2zz thanks so much for the time you put into redux-persist and redux-persist-migrate before v5. 👏👏👏 |
@aguynamedben yep all worked as expected once the fix was in. |
I tried it but rehydration comes
undefined
The text was updated successfully, but these errors were encountered: