Repository: reduxjs/redux-toolkit

Problem statement:
More control over serializableCheck option in middleware?
I'm using redux-toolkit with redux-persist. In order to avoid serialization errors, middleware is configured to ignore redux-persist actions:

```
 serializableCheck: {
 		ignoredActions: [FLUSH, REHYDRATE, PAUSE, PERSIST, PURGE, REGISTER]
},
```

I don't see a point of checking if actions are serializable if I am not using time-travel or other features. If action has a payload that is not serializable, it doesn't mean I am going to put that data as-is in the store. For example, my app works with dates and I would like to use dates in actions and store them in the state as strings. Or I might be using Set or Map to send data in action, but reducer will store that data as serializable data in the store.

Is there any option to skip checking **only for actions**? All of them? But leave this checking for the state.

I expected something like this, but this is not working:

```
 serializableCheck: {
 		ignoredActions: ['*']
},
```


Hints:

Patch:
diff --git a/packages/toolkit/src/serializableStateInvariantMiddleware.ts b/packages/toolkit/src/serializableStateInvariantMiddleware.ts
--- a/packages/toolkit/src/serializableStateInvariantMiddleware.ts
+++ b/packages/toolkit/src/serializableStateInvariantMiddleware.ts
@@ -132,9 +132,14 @@ export interface SerializableStateInvariantMiddlewareOptions {
   warnAfter?: number
 
   /**
-   * Opt out of checking state, but continue checking actions
+   * Opt out of checking state. When set to `true`, other state-related params will be ignored.
    */
   ignoreState?: boolean
+
+  /**
+   * Opt out of checking actions. When set to `true`, other action-related params will be ignored.
+   */
+  ignoreActions?: boolean
 }
 
 /**
@@ -160,10 +165,14 @@ export function createSerializableStateInvariantMiddleware(
     ignoredPaths = [],
     warnAfter = 32,
     ignoreState = false,
+    ignoreActions = false,
   } = options
 
   return (storeAPI) => (next) => (action) => {
-    if (ignoredActions.length && ignoredActions.indexOf(action.type) !== -1) {
+    if (
+      ignoreActions ||
+      (ignoredActions.length && ignoredActions.indexOf(action.type) !== -1)
+    ) {
       return next(action)
     }
 


Test patch:
diff --git a/packages/toolkit/src/tests/serializableStateInvariantMiddleware.test.ts b/packages/toolkit/src/tests/serializableStateInvariantMiddleware.test.ts
--- a/packages/toolkit/src/tests/serializableStateInvariantMiddleware.test.ts
+++ b/packages/toolkit/src/tests/serializableStateInvariantMiddleware.test.ts
@@ -389,6 +389,30 @@ describe('serializableStateInvariantMiddleware', () => {
     })
   })
 
+  it('allows ignoring actions entirely', () => {
+    let numTimesCalled = 0
+
+    const serializableStateMiddleware =
+      createSerializableStateInvariantMiddleware({
+        isSerializable: () => {
+          numTimesCalled++
+          return true
+        },
+        ignoreActions: true,
+      })
+
+    const store = configureStore({
+      reducer: () => ({}),
+      middleware: [serializableStateMiddleware],
+    })
+
+    expect(numTimesCalled).toBe(0)
+
+    store.dispatch({ type: 'THIS_DOESNT_MATTER' })
+
+    expect(numTimesCalled).toBe(0)
+  })
+
   it('should not check serializability for ignored slice names', () => {
     const ACTION_TYPE = 'TEST_ACTION'