From 769b4d68bfb68da2aaec64ed1340bf6e88722897 Mon Sep 17 00:00:00 2001 From: Anton Nikolaev Date: Tue, 2 Mar 2021 12:08:03 -0800 Subject: [PATCH] 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 --- desktop/app/src/reducers/connections.tsx | 32 ++++++++++++++++++------ 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/desktop/app/src/reducers/connections.tsx b/desktop/app/src/reducers/connections.tsx index ce46256ee..0c8b609c8 100644 --- a/desktop/app/src/reducers/connections.tsx +++ b/desktop/app/src/reducers/connections.tsx @@ -31,22 +31,35 @@ export type StaticView = | ComponentType | React.FunctionComponent; -export type State = StateV1; +export type State = StateV2; -export const persistVersion = 1; +export const persistVersion = 2; export const persistMigrations = { 1: (state: any) => { const stateV0 = state as StateV0; const stateV1 = { ...stateV0, - enabledPlugins: stateV0.userStarredPlugins, - enabledDevicePlugins: stateV0.userStarredDevicePlugins, + enabledPlugins: stateV0.userStarredPlugins ?? {}, + enabledDevicePlugins: + stateV0.userStarredDevicePlugins ?? + new Set(INITAL_STATE.enabledDevicePlugins), }; return stateV1 as any; }, + 2: (state: any) => { + const stateV1 = state as StateV1; + const stateV2 = { + ...stateV1, + enabledPlugins: stateV1.enabledPlugins ?? {}, + enabledDevicePlugins: + stateV1.enabledDevicePlugins ?? + new Set(INITAL_STATE.enabledDevicePlugins), + }; + return stateV2 as any; + }, }; -type StateV1 = { +type StateV2 = { devices: Array; androidEmulators: Array; selectedDevice: null | BaseDevice; @@ -67,9 +80,14 @@ type StateV1 = { staticView: StaticView; }; +type StateV1 = Omit & { + enabledPlugins?: {[client: string]: string[]}; + enabledDevicePlugins?: Set; +}; + type StateV0 = Omit & { - userStarredPlugins: {[client: string]: string[]}; - userStarredDevicePlugins: Set; + userStarredPlugins?: {[client: string]: string[]}; + userStarredDevicePlugins?: Set; }; export type Action =