Skip to content

Commit 8511ce9

Browse files
committed
persist: On error deserializing, don't store null
We don't use these nulls in any later handling; they go into the REHYDRATE payload, but then in redux-persist-migrate we cast them away to pretend they can't be there. It's not clear how we would usefully do anything with them, either. Instead, on an error here just omit that key, the same as we would if it weren't there in the underlying storage at all. This lets us cut out a fixme step in redux-persist-migrate. The type of the REHYDRATE payload is still a lie, but it's now the same lie on its way into this code as out of it.
1 parent c017b39 commit 8511ce9

File tree

3 files changed

+4
-9
lines changed

3 files changed

+4
-9
lines changed

src/actionTypes.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,12 @@ import type {
106106
*
107107
* @prop payload A version of the global Redux state, as persisted by the
108108
* app's previous runs. This will be empty on first startup or if the
109-
* persisted state is just missing keys, and will have `null` at each
110-
* key where an error was encountered in reading the persisted state.
111-
* In any case it will only contain the keys we configure to be persisted.
109+
* persisted state is just missing keys. In any case it will only
110+
* contain the keys we configure to be persisted.
112111
*/
113112
type RehydrateAction = $ReadOnly<{|
114113
type: typeof REHYDRATE,
115-
+payload: $ReadOnly<$ObjMap<$Rest<GlobalState, { ... }>, <V>(V) => V | null>>,
114+
+payload: $ReadOnly<$Rest<GlobalState, { ... }>>,
116115
|}>;
117116

118117
type AppOnlineAction = $ReadOnly<{|

src/redux-persist-migrate/index.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,7 @@ export default function createMigration(
2525

2626
const migrationDispatch = next => (action: Action) => {
2727
if (action.type === REHYDRATE) {
28-
/* $FlowIgnore[incompatible-type]
29-
this really is a lie -- and kind of central to migration */
30-
const incomingState: State = action.payload;
31-
return next({ ...action, payload: migratePayload(incomingState) });
28+
return next({ ...action, payload: migratePayload(action.payload) });
3229
}
3330
return next(action);
3431
};

src/third/redux-persist/getStoredState.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ export default async function getStoredState(config: Config): Promise<{ ... }> {
4848
message: 'redux-persist/getStoredState: Error restoring data for a key.',
4949
key,
5050
});
51-
restoredState[key] = null;
5251
}
5352
})(),
5453
),

0 commit comments

Comments
 (0)