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

Infinite Loop when maximum update depth exceeds #3251

Closed
imanushree opened this issue Oct 7, 2017 · 9 comments
Closed

Infinite Loop when maximum update depth exceeds #3251

imanushree opened this issue Oct 7, 2017 · 9 comments
Milestone

Comments

@imanushree
Copy link

imanushree commented Oct 7, 2017

Is this a bug report?

Yes

Can you also reproduce the problem with npm 4.x?

Yes.

Which terms did you search for in User Guide?

not present in guide

Environment

  1. node -v: v6.11.0
  2. npm -v: 4.6.1
  3. yarn --version (if you use Yarn):
  4. npm ls react-scripts (if you haven’t ejected): 1.0.14

Then, specify:

  1. Operating system: Ubuntu
  2. Browser and version (if relevant): chrome 59

Steps to Reproduce

Generate a CRA app using React 16 and use this snippet below:

class App extends Component {
  constructor() {
    super();
    this.state = {
      value: null,
    };
  }

  render() {
    this.setState({
      value: 'test',
    });

    return <div />;
  }
}

Expected Behavior

When you have a react component with a nested update error, you get this error:

'Uncaught Error: 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.'

The error should print once to the console and the execution should stop.

Actual Behavior

But the execution did not stop. It was going in an infinite loop and printing 2 variants of the same error one after another. Initially assumed it to be a react issue(11136), but turns out:

This happens only in React 16 apps that are created using CRA.

Screenshot for your reference:
react-bug

@lazyd3v
Copy link

lazyd3v commented Oct 7, 2017

I think it's not a bug in react/cra etc. facebook/react#11113 have just not released yet. It's only in master branch, but not in last release (16.0.0) :)

@gaearon
Copy link
Contributor

gaearon commented Oct 7, 2017

facebook/react#11113 is about deduplication of warnings, but this one is a hard error. If it keeps happening more than once, then it's a bug somewhere. (Likely in our error overlay.)

Note that this doesn't reproduce outside of CRA environment.

@Timer
Copy link
Contributor

Timer commented Oct 8, 2017

This doesn't repro on master, so I assume it was fixed in our iframe execution isolation.

@Timer Timer added this to the 1.0.15 milestone Oct 11, 2017
@gaearon
Copy link
Contributor

gaearon commented Oct 28, 2017

Verified it happens on stable but not on master, and that copy-pasting latest react-scripts into a project with this fixes the issue. Thanks for a great report though! Was very easy to verify.

@gaearon gaearon closed this as completed Oct 28, 2017
@gaearon
Copy link
Contributor

gaearon commented Oct 30, 2017

clane pushed a commit to clane/React-A11y-Repo that referenced this issue Jan 5, 2018
@AlexKutschera
Copy link

This happened for me in react-scripts 1.0.0 and 1.1.1 too

@pietmichal
Copy link

pietmichal commented Feb 19, 2018

Had the same error when my routing configuration caused an infinite loop of redirects. It wasn't caused by setState pointed by CRA though.

@aje
Copy link

aje commented Jul 19, 2018

You shouldn't do setState in render() function, it causes loop.

so it's a bug in your code

@doughless
Copy link

You shouldn't do setState in render() function, it causes loop.

so it's a bug in your code

That was on purpose in the example. That was done to trigger the invalid infinite loop, and then another part of the code is supposed to detect this and halt execution. The actual bug was in the detection code; putting the intentional bug in the example was to purposely trigger the detection code.

@lock lock bot locked and limited conversation to collaborators Jan 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

8 participants