diff --git a/web/database/utils/constants.js b/web/database/utils/constants.js --- a/web/database/utils/constants.js +++ b/web/database/utils/constants.js @@ -18,7 +18,6 @@ 'edge', 'edge-chromium', 'chrome', - 'safari', 'firefox', 'opera', ]; diff --git a/web/redux/create-async-migrate.js b/web/redux/create-async-migrate.js --- a/web/redux/create-async-migrate.js +++ b/web/redux/create-async-migrate.js @@ -1,8 +1,12 @@ // @flow +import { getStoredState, purgeStoredState } from 'redux-persist'; import { DEFAULT_VERSION } from 'redux-persist/es/constants.js'; +import storage from 'redux-persist/es/storage/index.js'; import type { PersistState } from 'redux-persist/es/types.js'; +import { databaseModule } from '../database/database-module-provider.js'; + type MigrationManifest = { +[number | string]: (PersistedState) => Promise, }; @@ -24,10 +28,24 @@ currentVersion: number, ): Promise { if (!state) { + const isSupported = await databaseModule.isDatabaseSupported(); + if (!isSupported) { + if (debug) { + console.log('redux-persist: no inbound state, skipping migration'); + } + return undefined; + } + + const oldStorage = await getStoredState({ storage, key: 'root' }); + if (!oldStorage) { + return undefined; + } + + state = oldStorage; + purgeStoredState({ storage, key: 'root' }); if (debug) { - console.log('redux-persist: no inbound state, skipping migration'); + console.log('redux-persist: migrating state to SQLite storage'); } - return undefined; } const inboundVersion: number = state?._persist?.version ?? DEFAULT_VERSION; diff --git a/web/root.js b/web/root.js --- a/web/root.js +++ b/web/root.js @@ -7,7 +7,6 @@ import { composeWithDevTools } from 'redux-devtools-extension/logOnlyInProduction.js'; import { persistReducer, persistStore } from 'redux-persist'; import { PersistGate } from 'redux-persist/es/integration/react.js'; -import storage from 'redux-persist/es/storage/index.js'; import thunk from 'redux-thunk'; import { reduxLoggerMiddleware } from 'lib/utils/action-logger.js'; @@ -19,6 +18,7 @@ import { isSQLiteSupported } from './database/utils/db-utils.js'; import ErrorBoundary from './error-boundary.react.js'; import Loading from './loading.react.js'; +import commReduxStorageEngine from './redux/comm-redux-storage-engine.js'; import { createAsyncMigrate } from './redux/create-async-migrate.js'; import { reducer } from './redux/redux-setup.js'; import type { AppState, Action } from './redux/redux-setup.js'; @@ -80,7 +80,7 @@ const persistConfig = { key: 'root', - storage, + storage: commReduxStorageEngine, whitelist: isDatabaseSupported ? persistWhitelist : [...persistWhitelist, 'draftStore'],