leoasis / redux-immutable-state-invariant

Redux middleware that detects mutations between and outside redux dispatches. For development use only.
MIT License
937 stars 37 forks source link

doesn't work with redux-devtools-extension #40

Open desm opened 5 years ago

desm commented 5 years ago

I use the following TypeScript code to setup Redux' middlewares: (Note: for dev purposes only)

if (typeof window !== 'undefined') {
  if ((window as any).__REDUX_DEVTOOLS_EXTENSION__) {
    enhancer = compose(
      installReduxLoop(),
      (window as any).__REDUX_DEVTOOLS_EXTENSION__({ trace: true, traceLimit: 25 }),
      applyMiddleware(require('redux-immutable-state-invariant').default())
    )
  }
  // ...
}

I have found that I need to comment out the call to __REDUX_DEVTOOLS_EXTENSION__(...) in order for redux-immutable-state-invariant to work properly, otherwise incorrect mutations are detected for everything. Perhaps a note could be added that the 2 middlewares/extensions are incompatible? Thanks.

j1m-renwick commented 4 years ago

If it helps, I've had success with the following setup that doesn't call REDUX_DEVTOOLS_EXTENSION directly:

import {applyMiddleware, compose, createStore} from "redux";
import myReducer from "./reducers/myReducer";
import {install} from "redux-loop";
import {default as installInvariant} from 'redux-immutable-state-invariant';

const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;

export const store = createStore(
    myReducer,
    {}, 
    composeEnhancers(

        applyMiddleware(
            installInvariant()),
            install()));
cksachdev commented 3 years ago

@j1m-renwick I tried the approach you suggested, but I am still getting the window is not defined.

event - compiled successfully
ReferenceError: window is not defined
    at eval (webpack-internal:///./src/redux/store/configureStore.dev.js:18:26)
desm commented 7 months ago

I'm sorry for the late reply. You can close this issue if you'd like.