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.

Material-UI: too many re-renders. The layout is unstable.

See original GitHub issue
  • The issue is present in the latest release.
  • I have searched the issues of this repository and believe that this is not a duplicate.

Current Behavior 😯

When typing a large input into a <TextField>, eventually the following error pops up in the console

Material-UI: too many re-renders. The layout is unstable.
TextareaAutosize limits the number of renders to prevent an infinite loop.

Expected Behavior 🤔

For this to not happen

Steps to Reproduce 🕹

Just type a lot into the <TextField>.

Context 🔦

Just trying to write a long input into <TextField>.

Your Environment 🌎

Tech Version
Material-UI v4.9.5
React 16.13.0
Browser Firefox 74
TypeScript 3.8.3

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10 (2 by maintainers)

github_iconTop GitHub Comments

6reactions
azouaoui-medcommented, Jun 1, 2022

having the same issue when using <TextField multiline ...

so when the size changes vertically (from adding content to the input) i get this error i also noticed that it happens when controlled

MUI: Too many re-renders. The layout is unstable. 
TextareaAutosize limits the number of renders to prevent an infinite loop.  at TextareaAutosize

codesandbox demo

using @mui/material@5.16.1 and react@18.1.0

Screenshot from 2022-05-10 21-18-35

2reactions
marckornbergercommented, Jun 1, 2022

I just now found a fix for this issue: It wasn’t caused by MUI but by my incorrect usage of react-hook-form.

I assumed using the register method like with native HTML <input /> elements would work fine. With UI Libraries like MUI you should acutally use a Controller to wrap you form fields:

<Controller
  name='name'
  control={control}
  rules={{ required: 'Please enter a name!' }}
  render={({ field }) => (
    <TextField
      label='Name'
      multiline
      rows={3}
      variant='filled'
      {...field}
      disabled={loading}
      error={errors.name!== undefined}
      helperText={errors.name?.message}
    />
  )}
/>
Read more comments on GitHub >

github_iconTop Results From Across the Web

Material-UI: Too many re-renders. The layout is unstable ...
After some 10 or more 'onChange' happen, I get this error on the console: Material-UI: Too many re-renders. The layout is unstable.
Read more >
How to solve too many re-renders error in ReactJS?
“Too many re-renderers” is a React error that happens after you have reached an infinite render loop, typically caused by code that in...
Read more >
The error "Too many re-renders. React limits the number of ...
The issue is that the setCounter function gets invoked when the component renders, updates the state, which causes a re-render and does that...
Read more >
[Resolved] Too many re-renders. React limits the number of ...
React limits the number of renders to prevent an infinite loop. React Modal too many re-renders; React setState too many re-renders; This issue ......
Read more >
Too many re-renders React limits the number of ... - YouTube
how to solve Error: Too many re - renders. React limits the number of renders to prevent an infinite loop in react JS...
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