Context here: https://phab.comm.dev/D10784#inline-66023.
This code provides functions that handle resetting the user state after migration failure. As a result, this code should also cause the deletion database and clear auth metadata.
Right now this code causes logging out - recovering on native is tracked in ENG-6546.
Why do we need different nonUserSpecificFields here:
The result of handleReduxMigrationFailure is passed directly to the REHYDRATE action, and redux does not merge modified keys with the default state. And we have this flow:
- redux-persist rehydrates only persisted state - not full AppState
- We call this code on the failure, it goes through the state and reasign nonUserSpecificFields.
- If the field is nonUserSpecificFields but it hasn't persisted it gets overridden with undefined - an example is loadingStatuses.
- REHYDRATE action skips e.g. loadingStatuses because it was modified without merging with default state.
- We end up with loadingStatuses: undefined which is not what is described by types and causes errors in selectors.
To mitigate that, in this particular case when we reset the state after a failed migration we want to reset only persisted fields, for others we should use default ones (those are always used as default on app start).
Not sure if this is the cleanest solution but couldn't think of anything better.