arnthor3 / react-bootstrap-toggle

Bootstrap-toggle without the JQuery dependencies
Other
54 stars 16 forks source link

Jest infinite loop #31

Closed janderssen closed 5 years ago

janderssen commented 5 years ago

Get a infinite render loop when using jest for testing if I use this component:

[Invariant Violation: Maximum update depth exceeded. This can happen when a component repeatedly calls setState inside componentWillUpdate or componentDidUpdate. React limits the number of nested updates to prevent infinite loops.]

To work around for the moment, I remove the this.setDimensions(); from componentDidUpdate, but not sure if this is the correct fix as I dont know the Toggle code, just verifying if this seems to be an ok fix by the author?

arnthor3 commented 5 years ago

Or another option would be to set the width and height in the tests if you are able to. And also there is another much better option than this toggle, React-Toggle.

0xStarcat commented 4 years ago

I'm having this issue too. Tried setting width / height per this unrelated thread: https://github.com/testing-library/react-testing-library/issues/353#issuecomment-510074776

no luck.

0xStarcat commented 4 years ago

My solution was to pass a static height / width prop to the toggle which prevents setDimensions from being called.

Here's the bit of code causing the issue in the toggle:

componentDidMount() {
    if (this.props.width && this.props.height) {
      return;
    }
    this.setDimensions();
    if (this.props.recalculateOnResize) {
      this.resizeObserver = new ResizeObserver((ent, obs) => {
        this.setDimensions();
      });
      this.resizeObserver.observe(this.parent);
    }
  }
downtownadambrown commented 4 years ago

This is still an ongoing issue. This has proved to be a big problem for our production environment suddenly.