Page MenuHomePhabricator

D7668.id26355.diff
No OneTemporary

D7668.id26355.diff

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<PersistedState>,
};
@@ -24,10 +28,24 @@
currentVersion: number,
): Promise<PersistedState> {
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'],

File Metadata

Mime Type
text/plain
Expires
Sun, Nov 24, 10:11 AM (21 h, 51 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2574967
Default Alt Text
D7668.id26355.diff (2 KB)

Event Timeline