Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: disable immutable & serializable checks for redux store in production #190

Merged
merged 5 commits into from
Feb 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Not released
- Refactor on basic JSX & JS stuff [#170](https://github.com/CartoDB/carto-react-template/pull/170)
- Fix error on supportedBrowsers path [#170](https://github.com/CartoDB/carto-react-template/pull/170)
- Disable immutable & serializable checks for redux store on production [#190](https://github.com/CartoDB/carto-react-template/pull/190)

## 1.0.0-beta11 (2021-02-02)
- Remove datasets section [#175](https://github.com/CartoDB/carto-react-template/pull/175)
Expand Down
31 changes: 22 additions & 9 deletions template-sample-app/template/src/config/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,20 +71,33 @@ const staticReducers = {
app: appSlice,
};

function getCustomMiddleware() {
const devConfig = {
immutableCheck: {
ignoredPaths: ['carto.viewportFeatures'],
},
serializableCheck: {
ignoredPaths: ['carto.viewportFeatures'],
ignoredActions: ['carto/setViewportFeatures'],
},
};

const prodConfig = {
immutableCheck: false,
serializableCheck: false,
};

const isProductionEnv = process.env.NODE_ENV === 'production';

return getDefaultMiddleware(isProductionEnv ? prodConfig : devConfig);
}

// Configure the store
export default function configureAppStore() {
const reducerManager = createReducerManager(staticReducers);
store = configureStore({
reducer: reducerManager.reduce,
middleware: getDefaultMiddleware({
immutableCheck: {
ignoredPaths: ['carto.viewportFeatures'],
},
serializableCheck: {
ignoredPaths: ['carto.viewportFeatures'],
ignoredActions: ['carto/setViewportFeatures'],
},
}),
middleware: getCustomMiddleware(),
});

store.reducerManager = reducerManager;
Expand Down
15 changes: 14 additions & 1 deletion template-skeleton/template/src/config/store.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { combineReducers, configureStore } from '@reduxjs/toolkit';
import { combineReducers, configureStore, getDefaultMiddleware } from '@reduxjs/toolkit';
import appSlice from './appSlice';

let store = {};
Expand Down Expand Up @@ -71,11 +71,24 @@ const staticReducers = {
app: appSlice,
};

function getCustomMiddleware() {

const prodConfig = {
immutableCheck: false,
serializableCheck: false,
};

const isProductionEnv = process.env.NODE_ENV === 'production';

return isProductionEnv ? getDefaultMiddlerware(prodConfig) : getDefaultMiddleware();
}

// Configure the store
export default function configureAppStore() {
const reducerManager = createReducerManager(staticReducers);
store = configureStore({
reducer: reducerManager.reduce,
middleware: getCustomMiddleware(),
});

store.reducerManager = reducerManager;
Expand Down