diff --git a/src/js/electron/tron/migrations.ts b/src/js/electron/tron/migrations.ts index 1785cc4b26..fe81734a5e 100644 --- a/src/js/electron/tron/migrations.ts +++ b/src/js/electron/tron/migrations.ts @@ -42,7 +42,7 @@ export default async function migrations( run(state: VersionedData, migrations: Migration[]) { for (const {version, migrate} of migrations) { - state.data = migrate(state.data) + state.data = state.data ? migrate(state.data) : undefined state.version = version } return state diff --git a/src/js/state/migrations/202101201109_moveQueriesStateToGlobal.test.ts b/src/js/state/migrations/202101201109_moveQueriesStateToGlobal.test.ts index 3670deeda1..8234bda320 100644 --- a/src/js/state/migrations/202101201109_moveQueriesStateToGlobal.test.ts +++ b/src/js/state/migrations/202101201109_moveQueriesStateToGlobal.test.ts @@ -1,6 +1,14 @@ import getTestState from "../../test/helpers/getTestState" import migrate from "./202101201109_moveQueriesStateToGlobal" +test("when there are no windows", () => { + const {data} = getTestState("v0.22.0") + data.windows = {} + data.order = [] + const next = migrate(data) + expect(next.globalState.queries).toBe(undefined) +}) + test("migrating 202101201109_moveQueriesStateToGlobal", () => { let {data} = getTestState("v0.22.0") diff --git a/src/js/state/migrations/202101201109_moveQueriesStateToGlobal.ts b/src/js/state/migrations/202101201109_moveQueriesStateToGlobal.ts index 2a45d9d246..58e633516f 100644 --- a/src/js/state/migrations/202101201109_moveQueriesStateToGlobal.ts +++ b/src/js/state/migrations/202101201109_moveQueriesStateToGlobal.ts @@ -4,6 +4,13 @@ export default function moveQueriesStateToGlobal(state: any) { // Migrate state here const mergedQueryMap = {} const mergedQueryItems = [] + const windows = Object.values(state.windows) + + if (windows.length === 0) { + state.globalState.queries = undefined + return state + } + for (const s of getAllStates(state)) { if (!s.queries) continue s.queries.items.forEach((q) => {