Skip to content
This repository was archived by the owner on Aug 31, 2022. It is now read-only.

Commit e3599bc

Browse files
committed
Verify dashboard version before rehydrating redux store during deployments
1 parent 379b05e commit e3599bc

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"precommit": "npm run lint-staged",
88
"start": "cross-env UMI_UI=none umi dev",
99
"start:no-mock": "cross-env MOCK=none umi dev",
10-
"build": "umi build",
10+
"build": "npm --no-git-tag-version version prerelease && umi build",
1111
"site": "umi-api-doc static && gh-pages -d dist",
1212
"analyze": "cross-env ANALYZE=true umi build",
1313
"lint:style": "stylelint \"src/**/*.less\" --syntax less",

src/app.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { persistStore, persistReducer } from 'redux-persist';
22
import storage from 'redux-persist/lib/storage';
33

4+
import { version } from '../package.json';
45
import { getAppPath } from './utils/utils';
56

67
/*
@@ -18,8 +19,15 @@ const persistConfig = {
1819
};
1920

2021
const persistEnhancer = () => createStore => (reducer, initialState, enhancer) => {
22+
const cachedVersionId = window.localStorage.getItem('versionId');
23+
if (cachedVersionId && cachedVersionId !== version && process.env.NODE_ENV === 'production') {
24+
window.localStorage.clear();
25+
}
26+
window.localStorage.setItem('versionId', version);
27+
2128
const store = createStore(persistReducer(persistConfig, reducer), initialState, enhancer);
2229
const persist = persistStore(store, null);
30+
2331
return {
2432
persist,
2533
...store,

0 commit comments

Comments
 (0)