question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Infinite Loop when maximum update depth exceeds

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

7reactions
ajecommented, Jul 19, 2018

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

so it’s a bug in your code

6reactions
gaearoncommented, 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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ReactJS: Maximum update depth exceeded error
Maximum update depth exceeded. This can happen when a component repeatedly calls setState inside componentWillUpdate or componentDidUpdate.
Read more >
Fix the "Maximum Update Depth Exceeded" Error in React
One of which is when you accidentally cause an infinite render loop, often resulting in the cryptic “maximum update depth exceeded” error.
Read more >
Maximum update depth exceeded warning in React
Maximum update depth exceeded warning in React ... This warning can often happen when a component sets the state inside the useEffect hook....
Read more >
How to Fix Maximum Update Depth Exceeded in React and ...
In this video, I show you several ways the dreaded "Max Update Depth Exceeded " error commonly occurs in React and React Native...
Read more >
Maximum update depth exceeded problem without using ...
"Warning: Maximum update depth exceeded. This can happen when a component calls setState inside useEffect, but useEffect either doesn't have ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found