Fix issue with migration producing undefined state for enabled plugins
Summary: I've modified migration to ensure it never produces "undefined" state. Before that this happened when migration is performed from version 0.75- to 0.77+ without 0.76 in between. Reviewed By: mweststrate Differential Revision: D26749830 fbshipit-source-id: 3a6599e80935060e8784103363abd617a7f1b7bd
This commit is contained in:
committed by
Facebook GitHub Bot
parent
390f27a137
commit
769b4d68bf
@@ -31,22 +31,35 @@ export type StaticView =
|
|||||||
| ComponentType<StaticViewProps>
|
| ComponentType<StaticViewProps>
|
||||||
| React.FunctionComponent<any>;
|
| React.FunctionComponent<any>;
|
||||||
|
|
||||||
export type State = StateV1;
|
export type State = StateV2;
|
||||||
|
|
||||||
export const persistVersion = 1;
|
export const persistVersion = 2;
|
||||||
export const persistMigrations = {
|
export const persistMigrations = {
|
||||||
1: (state: any) => {
|
1: (state: any) => {
|
||||||
const stateV0 = state as StateV0;
|
const stateV0 = state as StateV0;
|
||||||
const stateV1 = {
|
const stateV1 = {
|
||||||
...stateV0,
|
...stateV0,
|
||||||
enabledPlugins: stateV0.userStarredPlugins,
|
enabledPlugins: stateV0.userStarredPlugins ?? {},
|
||||||
enabledDevicePlugins: stateV0.userStarredDevicePlugins,
|
enabledDevicePlugins:
|
||||||
|
stateV0.userStarredDevicePlugins ??
|
||||||
|
new Set<string>(INITAL_STATE.enabledDevicePlugins),
|
||||||
};
|
};
|
||||||
return stateV1 as any;
|
return stateV1 as any;
|
||||||
},
|
},
|
||||||
|
2: (state: any) => {
|
||||||
|
const stateV1 = state as StateV1;
|
||||||
|
const stateV2 = {
|
||||||
|
...stateV1,
|
||||||
|
enabledPlugins: stateV1.enabledPlugins ?? {},
|
||||||
|
enabledDevicePlugins:
|
||||||
|
stateV1.enabledDevicePlugins ??
|
||||||
|
new Set<string>(INITAL_STATE.enabledDevicePlugins),
|
||||||
|
};
|
||||||
|
return stateV2 as any;
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
type StateV1 = {
|
type StateV2 = {
|
||||||
devices: Array<BaseDevice>;
|
devices: Array<BaseDevice>;
|
||||||
androidEmulators: Array<string>;
|
androidEmulators: Array<string>;
|
||||||
selectedDevice: null | BaseDevice;
|
selectedDevice: null | BaseDevice;
|
||||||
@@ -67,9 +80,14 @@ type StateV1 = {
|
|||||||
staticView: StaticView;
|
staticView: StaticView;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type StateV1 = Omit<StateV2, 'enabledPlugins' | 'enabledDevicePlugins'> & {
|
||||||
|
enabledPlugins?: {[client: string]: string[]};
|
||||||
|
enabledDevicePlugins?: Set<string>;
|
||||||
|
};
|
||||||
|
|
||||||
type StateV0 = Omit<StateV1, 'enabledPlugins' | 'enabledDevicePlugins'> & {
|
type StateV0 = Omit<StateV1, 'enabledPlugins' | 'enabledDevicePlugins'> & {
|
||||||
userStarredPlugins: {[client: string]: string[]};
|
userStarredPlugins?: {[client: string]: string[]};
|
||||||
userStarredDevicePlugins: Set<string>;
|
userStarredDevicePlugins?: Set<string>;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type Action =
|
export type Action =
|
||||||
|
|||||||
Reference in New Issue
Block a user