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.

ComponentPlayground – Maximum update depth exceeded

See original GitHub issue

Describe Your Environment

What version of Spectacle are you using? (can be found by running npm list spectacle) spectacle@5.2.2

What version of React are you using? (can be found by running npm list react) react@16.6.3

What browser are you using? Chrome@70.0.3538.110

What machine are you on? macOS@10.14.1

Describe the Problem

When using the ComponentPlayground component with custom code an endless update cycle is started.

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.

Like the error message describes the problem, the ComponentPlayground is updating itself due enhancing the scope with Component class from React. When getDerivedStateFrom is comparing both previous scope (inside state) and the new one (from props), it actually compares my custom scope with the enhanced one. This of course will never be true and leads to the endless loop described above.

  static getDerivedStateFromProps(nextProps, prevState) {
    const updatedState = {};
    if (nextProps.code !== prevState.code) {
      const code = (nextProps.code || defaultCode).trim();
      updatedState.code = code;
    }
    if (nextProps.scope !== prevState.scope) {
      const scope = getEnhancedScope(nextProps.scope);
      updatedState.scope = scope;
    }
    return isEmpty(updatedState) ? null : updatedState;
  }

Possible Fix

A possible fix could be to enhance the scope on render when passed to the react-live components. This would make it possible to compare the scope stored in the state with the new one. (Although I really do not see any good reason for the ComponentPlayground to store the code and scope in state anyway.)

I you like I could create a PR with a possible fix. Already created a working ComponentPlayground component for my upcoming presentation.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

8reactions
dmitrifcommented, Apr 5, 2019

Any update on this? As of right now ComponentPlayground can be considered broken. Thank you in advance.

3reactions
ebrillhartcommented, Dec 3, 2018

Thanks for flagging @lennerd! We’ll look into this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

reactjs - How to fix: 'Error: Maximum update depth exceeded'
Error: Maximum update depth exceeded. This can happen when a component repeatedly calls setState inside componentWillUpdate or ...
Read more >
Maximum update depth exceeded but I passed in an empty ...
This gives maximum depth exceeded error since I'm setting state inside of useEffect(), but shouldn't the empty dependency array stop that? I'm ...
Read more >
"Maximum update depth exceeded" with version 7.1.0 · Issue ...
"Maximum update depth exceeded. This can happen when a component repeatedly calls setState inside componentWillUpdate or componentDidUpdate.
Read more >
MDBSelect Array of Options - Get Value Errors - MDBootstrap
Currently when I try to insert a function for getValue or getTextContent it produces the error Maximum update depth exceeded. This can happen...
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...
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