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

Chrome Error: Maximum Call Stack Exceeded #37

Open carpben opened 6 years ago

carpben commented 6 years ago

I think it's a very important library for the Redux community.

I installed the library locally according to the instructions. Here is a production version of the app https://next-f2cee.firebaseapp.com/. I expect there to be some mutations and I wonder where. However I received this error, which doesn't seem to relate to a redux/state mutation: image

Here is my index.js:

import React from 'react'
import { render } from 'react-dom'
import { Provider } from 'react-redux'
import { createStore, applyMiddleware, compose } from 'redux'
import nextApp from './reducers'
import AppContainer from './containers/AppContainer.js'
import thunk from 'redux-thunk'

const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;

const middlewares = process.env.NODE_ENV !== 'production' ?
  [require('redux-immutable-state-invariant').default(), thunk] :
  [thunk];

  const store = createStore(nextApp, composeEnhancers(applyMiddleware(...middlewares)));

//let store = createStore(nextApp)

render(
  <Provider store={store}>
    <AppContainer />
  </Provider>,
  document.getElementById('root')
)
carpben commented 6 years ago

I also tried to use ES6 modules as I usually do:

import React from 'react';
import { render } from 'react-dom';
import { Provider } from 'react-redux';
import { createStore, applyMiddleware, compose } from 'redux';
import nextApp from './reducers';
import AppContainer from './containers/AppContainer.js';
import thunk from 'redux-thunk';
import mutationShouter from 'redux-immutable-state-invariant';

const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;

const middlewares = process.env.NODE_ENV !== 'production' ?  [mutationShouter, thunk] : [thunk];

const store = createStore(nextApp, composeEnhancers(applyMiddleware(...middlewares)));

//let store = createStore(nextApp)

render(
  <Provider store={store}>
    <AppContainer />
  </Provider>,
  document.getElementById('root')
);

It resulted in an error:

TypeError: getState is not a function
(anonymous function)
C:/Users/carpb/projects/notifications/node_modules/redux-immutable-state-invariant/dist/index.js:41
  38 | return function (_ref) {
  39 |   var getState = _ref.getState;
  40 | 
> 41 |   var state = getState();
leoasis commented 6 years ago

This library works out of the box with POJOS and arrays and native JS types, so maybe this is happening because you have custom classes or Maps or Sets? If so, you can use something like isImmutable?

carpben commented 6 years ago

Sorry I'm not using ImmutableJS, just plain old JS objects. Perhaps I should mention that I'm working on Windows.

leoasis commented 6 years ago

Are you doing any kind of circular dependency in your JS objects? What seems to be happening is that an object may be referencing itself directly or indirectly, making the trackForMutations function never finish.

carpben commented 6 years ago

Probably not. If there was a circular dependency I'd expect the app not to work at all. But the app works on a daily basis. Isn't it so?

chirva-ivan commented 5 years ago

Got the same issue, it's appears after migration into latest version of "redux": "4.0.1"

santiagopuentep commented 5 years ago

Same issue here.