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

Consider enabling default middleware checks on Redux store #1712

Merged
merged 4 commits into from
Oct 17, 2023
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
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,18 @@ If you are editing source code, running the following command will allow hot-rel
auspice develop --datasetDir data
```

#### Environment variables

The client looks for some environment variables. All are optional.

> [!NOTE]
> This is an incomplete list. For other variables, search for `process.env.` in the codebase.

- `SKIP_REDUX_CHECKS`: Set this to a truthy value to improve dev server responsiveness. Useful when you see a console warning like this:

> ImmutableStateInvariantMiddleware took 200ms, which is more than the warning threshold of 32ms.
> If your state or actions are very large, you may want to disable the middleware as it might cause too much of a slowdown in development mode.

### CLI (Command Line Interface)

Run `auspice --help` or `auspice view --help` to see all the available command line options.
Expand Down
25 changes: 20 additions & 5 deletions src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,27 @@ const middleware = [
const store = configureStore({
reducer: rootReducer,
middleware: (getDefaultMiddleware) =>
// This adds the thunk middleware, and for development builds, other useful checks.
getDefaultMiddleware({
// TODO: Go through reducers and see why the state is not immutable nor serializable.
// These were not checked prior to the adoption of Redux Toolkit, and were not
// investigated to minimize conversion efforts.
immutableCheck: false,
serializableCheck: false
// Immutability can't be checked in some parts of the state due to circular references.
// Allow the option to disable this check through an environment variable.
// Note that it is never enabled when NODE_ENV=production.
immutableCheck: process.env.SKIP_REDUX_CHECKS
? false
: {
ignoredPaths: [
'tree.nodes',
'tree.vaccines',
'treeToo.nodes',
'treeToo.vaccines',
],
},

// By design, the state contains many values that are non-serializable.
// Instead of adding several ignoredPaths, disable this check entirely.
// This means time-travel debugging is not possible, but it would not be
// performant enough given the large size of the Redux state.
serializableCheck: false,
}).concat(middleware),
devTools: process.env.NODE_ENV !== 'production',
})
Expand Down
1 change: 1 addition & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ const generateConfig = ({extensionPath, devMode=false, customOutputPath, analyze
const pluginProcessEnvData = new webpack.DefinePlugin({
"process.env": {
NODE_ENV: devMode ? JSON.stringify("development") : JSON.stringify("production"),
SKIP_REDUX_CHECKS: JSON.stringify(process.env.SKIP_REDUX_CHECKS),
EXTENSION_DATA: JSON.stringify(extensionData)
}
});
Expand Down