material-ui: [TextField] `Too many re-renders. The layout is unstable.` error message with `multiline` enabled in controlled mode
Duplicates
- I have searched the existing issues
Latest version
- I have tested the latest version
Current behavior 😯
When using a multiline TextField in controlled mode the following error message in the console occurs multiple times:
MUI: Too many re-renders. The layout is unstable.
TextareaAutosize limits the number of renders to prevent an infinite loop.
Also, the text field is not correctly resized sometimes. When pressing a return sometimes no new line is added.
The error only happens in a controlled mode. The uncontrolled mode works fine.
Expected behavior 🤔
No error message. Correct resizing.
Steps to reproduce 🕹
Minimal StackBlitz sample: https://stackblitz.com/edit/react-ljalqg?file=demo.tsx
- Visit the above link
- Open and watch the StackBlitz console
- Focus the TextField and press enter several times
Context 🔦
No response
Your environment 🌎
`npx @mui/envinfo`
System:
OS: Linux 5.16 Ubuntu 20.04.4 LTS (Focal Fossa)
Binaries:
Node: 16.15.0 - ~/.nvm/versions/node/v16.15.0/bin/node
Yarn: 1.22.18 - ~/.nvm/versions/node/v16.15.0/bin/yarn
npm: 8.5.5 - ~/.nvm/versions/node/v16.15.0/bin/npm
Browsers:
Chrome: Not Found
Firefox: Not Found
npmPackages:
@emotion/react: ^11.9.0 => 11.9.0
@emotion/styled: ^11.8.1 => 11.8.1
@mui/base: 5.0.0-alpha.83
@mui/icons-material: ^5.8.2 => 5.8.2
@mui/lab: ^5.0.0-alpha.84 => 5.0.0-alpha.84
@mui/material: ^5.8.2 => 5.8.2
@mui/private-theming: 5.8.0
@mui/styled-engine: 5.8.0
@mui/system: 5.8.2
@mui/types: 7.1.3
@mui/utils: 5.8.0
@mui/x-date-pickers: 5.0.0-alpha.1
@types/react: 18.0.10 => 18.0.10
react: 18.1.0 => 18.1.0
react-dom: 18.1.0 => 18.1.0
typescript: 4.7.2 => 4.7.2
Using Chrome.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 19 (4 by maintainers)
Not really worried about the error messages lol. More worried about the performance issues.
same problem… versions:
“@mui/material”: “^5.13.7”, “react”: “^18.2.0”, I’m still encountering an error too
I’m currently facing an issue with the multiline functionality in the TextField component while using NodeJS 18.2 and MUI 5.13. Despite being on the latest versions, I’m still encountering an error. Whenever I try to use multiline, the TextField doesn’t behave as expected.
This issue always occurs for me (in a styled material TextField component , with some tailwind but nothing special) and the above code still fixes the issue in my case. Cannot really explain why it occurs for me and not for you guys. I ll try to investigate again soon
Do you and your teammate have different monitors? I had this happen when my textField was being constrained by css and couldn’t grow to target size.
Is there any sort of planned fix for this issue?
I’m still seeing it with the following versions:
I have checked the MUI docs and specifying rows should not be required, but if you dont set the row prop you get the bug.
I also tried setting minRows to 1 so the rest of the TextArea would resize automatically to fit the content but I got the same bug. If minRows is set to the exact number of rows you need + 1 you dont get the bug but if minRows is under or equal to the height of your TextArea you also get the problem.
The only solution that worked so far is setting the rows prop or setting the minRows prop to the number of rows of the text + 1, so I think it may be a problem of the autosizing calculation.
Is this the expexted behaviour of the component?? To require a rows input if multiline is true? This kind of defeats the purpose of auto-scaling up to the number of rows? I can confirm that if rows is not specified there is an infinite loop error. This is the version that I have: 5.14.11 Would this be looked into or this is the expected behaviour, just asking out of curiosity…
I encountered this error, and after some investigation, I realized that there is a bug in the
multilineprop of the TextField. If you don’t specify therowsprop, it goes into an infinite loop and triggers the error. I fixed it by setting therowsprop to ‘5’, and the error stopped occurring.This has been the solution that worked for me:
After this the infinite loop error was solved.