HomePhabricator
Diffusion Comm 4a27732fbab3

[lib][web][native] handle failed redux migrations

Description

[lib][web][native] handle failed redux migrations

Summary:
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:

  1. redux-persist rehydrates only persisted state - not full AppState
  2. We call this code on the failure, it goes through the state and reasign nonUserSpecificFields.
  3. If the field is nonUserSpecificFields but it hasn't persisted it gets overridden with undefined - an example is loadingStatuses.
  4. REHYDRATE action skips e.g. loadingStatuses because it was modified without merging with default state.
  5. 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.

Test Plan: Add migration that fails and run it, make sure it reset state, clear database and on native clears also auth metadata.

Reviewers: inka, tomek, ashoat

Reviewed By: inka, ashoat

Differential Revision: https://phab.comm.dev/D10955

Details

Provenance
kamilAuthored on Feb 5 2024, 1:13 PM
Reviewer
inka
Differential Revision
D10955: [lib][web][native] handle failed redux migrations
Parents
rCOMM8f5445cf7c9b: [lib] refactor `keyserverStoreOpsHandlers` to process ops on entireā€¦
Branches
Unknown
Tags
Unknown