Skip to content

Commit 863bca7

Browse files
jainkuniyagnprice
authored andcommitted
persist-migrate: Don't run old migrations on first install.
It turns out that `redux-persist-migrate` as taken from upstream wants to run all the migrations from scratch when `payload` in the REHYDRATE action is missing or empty -- which is what happens on first install. That would make each migration permanently a critical part of our code, on the path for every new user; and one that's rarely run in normal use, making bugs likely to slip through. In fact, there's no need for any migrations, and they wouldn't do much anyway, because the rehydrated state (`action.payload` aka `incomingState`) is an empty object. The state in the Redux store has already been initialized by the reducers to the right shape, from the `initialState` object in each reducer, when the store was first created. Instead, skip the migrations. Just set the version to the current one, so that future upgrades will run any new migrations they include. This fixes an issue introduced in c2ed78e, where migration 2 tries to update the shape of `state.realm.pushToken`, and on a fresh install would crash because there is no such property. [greg: expanded commit message]
1 parent 4736520 commit 863bca7

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/redux-persist-migrate/index.js

+4
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ export default function createMigration(manifest, versionSelector, versionSetter
5252
let incomingVersion = parseInt(versionSelector(incomingState), 10);
5353
if (Number.isNaN(incomingVersion)) {
5454
incomingVersion = null;
55+
// first launch after install, so initial state is empty object
56+
// migration not required, just update verion
57+
action.payload = versionSetter(incomingState, currentVersion);
58+
return next(action);
5559
}
5660

5761
if (incomingVersion !== currentVersion) {

0 commit comments

Comments
 (0)