From e3599bcec8fa60e5d558d8554b47a1d0b96d9ceb Mon Sep 17 00:00:00 2001 From: gurbirkalsi Date: Fri, 8 May 2020 12:08:03 -0400 Subject: [PATCH] Verify dashboard version before rehydrating redux store during deployments --- package.json | 2 +- src/app.js | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index e1194214e..9680006c5 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "precommit": "npm run lint-staged", "start": "cross-env UMI_UI=none umi dev", "start:no-mock": "cross-env MOCK=none umi dev", - "build": "umi build", + "build": "npm --no-git-tag-version version prerelease && umi build", "site": "umi-api-doc static && gh-pages -d dist", "analyze": "cross-env ANALYZE=true umi build", "lint:style": "stylelint \"src/**/*.less\" --syntax less", diff --git a/src/app.js b/src/app.js index 379577943..67f8c1d4f 100644 --- a/src/app.js +++ b/src/app.js @@ -1,6 +1,7 @@ import { persistStore, persistReducer } from 'redux-persist'; import storage from 'redux-persist/lib/storage'; +import { version } from '../package.json'; import { getAppPath } from './utils/utils'; /* @@ -18,8 +19,15 @@ const persistConfig = { }; const persistEnhancer = () => createStore => (reducer, initialState, enhancer) => { + const cachedVersionId = window.localStorage.getItem('versionId'); + if (cachedVersionId && cachedVersionId !== version && process.env.NODE_ENV === 'production') { + window.localStorage.clear(); + } + window.localStorage.setItem('versionId', version); + const store = createStore(persistReducer(persistConfig, reducer), initialState, enhancer); const persist = persistStore(store, null); + return { persist, ...store,