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

[TextareaAutosize] ResizeObserver loop completed with undelivered notifications (when resizing view with TextArea with scroll inside) #43718

Open
clement-faure opened this issue Sep 22, 2023 · 68 comments · May be fixed by #44540
Assignees
Labels
component: TextareaAutosize The React component. priority: important This change can make a difference

Comments

@clement-faure
Copy link

clement-faure commented Sep 22, 2023

Steps to reproduce 🕹

Link to live example:

https://codesandbox.io/p/sandbox/mui-resizeobserver-loop-error-d2w936

Steps:

  1. Create view with TextArea component
  2. Set rows props to 2
  3. Set default value to long text
  4. Try resizing view

Current behavior 😯

All seems to works fine at first view but sentry report a "ResizeObserver loop completed with undelivered notifications." error.

Expected behavior 🤔

No error should occur

Context 🔦

No response

Your environment 🌎

 System:
    OS: macOS 13.5.2
  Binaries:
    Node: 18.12.1 - ~/.nvm/versions/node/v18.12.1/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 8.19.2 - ~/.nvm/versions/node/v18.12.1/bin/npm
  Browsers:
    Chrome: 116.0.5845.187
    Edge: Not Found
    Safari: 16.6
  npmPackages:
    @emotion/react: ^11.11.1 => 11.11.1 
    @emotion/styled: ^11.11.0 => 11.11.0 
    @mui/base:  5.0.0-beta.16 
    @mui/core: ^5.0.0-alpha.54 => 5.0.0-alpha.54 
    @mui/core-downloads-tracker:  5.14.10 
    @mui/envinfo: ^2.0.9 => 2.0.9 
    @mui/icons-material: ^5.14.9 => 5.14.9 
    @mui/material: ^5.14.10 => 5.14.10 
    @mui/private-theming:  5.14.10 
    @mui/styled-engine:  5.14.10 
    @mui/system:  5.14.10 
    @mui/types:  7.2.4 
    @mui/utils:  5.14.10 
    @types/react: ^18.2.21 => 18.2.21 
    react: ^18.2.0 => 18.2.0 
    react-dom: ^18.2.0 => 18.2.0 
    typescript: ^5.2.2 => 5.2.2 

Search keywords:

Search keywords:

@clement-faure clement-faure added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Sep 22, 2023
@samuelsycamore

This comment was marked as resolved.

@samuelsycamore samuelsycamore added status: waiting for author Issue with insufficient information and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Oct 10, 2023
@ps-mladen-savic
Copy link

I have the same issue, when I add 'multiline' property to TextField.

@stevemckenzie

This comment was marked as resolved.

@github-actions

This comment was marked as resolved.

@ZonicaP

This comment was marked as resolved.

@marthrusk

This comment was marked as resolved.

@samuelsycamore
Copy link
Contributor

Reopening this since we're getting more reports that seem to be related. Can anyone share a reproduction of the problem?

@github-actions

This comment was marked as resolved.

@samuelsycamore samuelsycamore removed the status: waiting for author Issue with insufficient information label Oct 23, 2023
@ShafiaShahid

This comment was marked as resolved.

@ryan-saffer
Copy link

I was facing the same error, and also had multiline on my <TextField />. The error disappeared when I added the property rows={1} to the <TextField />.

I was unable to reproduce the error on CodePen, but hopefully this helps others!

@monteiz
Copy link

monteiz commented Nov 4, 2023

I can also confirm that using the multiline attribute in the TextField component is raising the exception ResizeObserver loop completed with undelivered notifications.

I am using:

"@mui/material": "^5.14.16",
"@mui/styles": "^5.14.16",
"react": "^17.0.2",
"react-dom": "^17.0.2"

It's worth noting that the warning appears occasionally on page refresh (about 80% of the times).

@ryan-saffer adding rows={1} as a workaround did not work for me. The only way is to remove the multiline attribute.

@monteiz
Copy link

monteiz commented Nov 4, 2023

I could at least isolate the problem. In my case, it was lying into the main mustache template. This is a simplified version that I hope it helps you to reproduce the issue:

<!doctype html>
<html>
	<head>
		<style>
			div.hidden {
				display: none !important;
			}
		</style>
	</head>

	<body>
		<div id="main" class="hidden">{{ html }}</div>

		<script
			src="https://localhost:9004/bundle.js?{{ webpack_hash }}"
			type="text/javascript"
		></script>

		<script>
			function hidePreloader() {
				const el = document.querySelector("#main");
				el.classList.remove("hidden"); // this line is causing the warning to appear
			}

			document.body.onload = hidePreloader;
		</script>
	</body>
</html>

The warning stops appearing if I comment out the line

el.classList.remove("hidden");

This is the client code, reduced to the minimum:

import React from "react";
import ReactDOM from "react-dom";
import TextField from "@mui/material/TextField/index.js";

const App = () => {
	return <TextField multiline></TextField>;
};

ReactDOM.render(<App />, document.querySelector("#main"));

@abuuer
Copy link

abuuer commented Nov 6, 2023

I faced the same error while using multiline inside <TextField />. The error seemed to be reproduced everytime I resize the page, and occurs at the exact moment when the scrollbar appears inside the TextField as shown in the second picture. The error disappears when I remove multiline. However, I am still trying to reproduce the error in codesandbox with no luck so far.
1 2

@Dzemik55
Copy link

Dzemik55 commented Nov 8, 2023

I also face this error. I use <TextField /> with multiline, fullWidth and maxRows={Infinity} and it happens when I resize the window. I tried to reproduce the error in codesandbox but it just doesn't occur there.

@cpetersonco
Copy link

I am also encountering this issue. It seems like this error is already being handled in the test environment, so we may need to apply the error handling here in TextareaAutosize.tsx to all environments.

@beyonditsolutions
Copy link

I have exactly the same issue with MUI 5.14.11! The only thing I can add, it only happens when the breakpoint SM (600px width) is passed!

@adamplonka
Copy link

adamplonka commented Nov 13, 2023

I'm having the same issue. Actually the whole code needed to reproduce this issue is just:

<Textarea />

Then put some long text in it and an error will appear whenever number of lines changes due to window resizing.

Codesandbox to reproduce:
https://codesandbox.io/s/compassionate-clarke-fzzvjv?file=/src/App.js

It happens only when the whole window resizes, so it doesn't work on codesandbox and webpack gives us a nasty red overlay with this error but in this example, I attached to the error window event to show the error in the console.

@TamNhiDuong
Copy link

I got the same problem with multiline TextInput. Reproduce by copying exact example code in MUI website:
<TextField id="outlined-multiline-static" label="Multiline" multiline rows={4} defaultValue="Default Value" />

And the error message is:

ERROR
ResizeObserver loop completed with undelivered notifications.
at handleError (http://localhost:3000/viewer4/static/js/bundle.js:175233:58)
at http://localhost:3000/viewer4/static/js/bundle.js:175252:7

@ChrisB1123
Copy link

I'm having the same issue. Actually the whole code needed to reproduce this issue is just:

<Textarea />

Then put some long text in it and an error will appear whenever number of lines changes due to window resizing.

Codesandbox to reproduce: https://codesandbox.io/s/compassionate-clarke-fzzvjv?file=/src/App.js

It happens only when the whole window resizes, so it doesn't work on codesandbox and webpack gives us a nasty red overlay with this error but in this example, I attached to the error window event to show the error in the console.

Similar issue to this for me. If I add the maxRows prop, then the error no longer appears.

@gvtrindade
Copy link

I've been having the same issue, but with the <TextareaAutosize /> component. Tried all tips reported in the issue that could solve the problem to no avail.

<TextareaAutosize
        id={id}
        className="question"
        style={{
          textAlign: "justify",
          width: "100%",
          resize: "none",
          outline: 0,
          color: disabled ? "#bcbec2" : "black"
        }}
      />

@mnajdova mnajdova assigned mj12albert and unassigned mnajdova and aarongarciah May 23, 2024
@paolobiavati
Copy link

paolobiavati commented May 27, 2024

In my case this error appears with the textarea fullWidth, due to window resize, everytimes the textarea changes the number of lines or show the scroll bar.
I found a workaround:
set rows to a fix number and give style overflow-y: scroll !important; to textarea:
// jsx

               <TextField
                    fullWidth
                    multiline
                    rows={6}
                />

// css

textarea {
    overflow-y: scroll !important;
}

@andreykuzmenko
Copy link

+1

@vitexikora
Copy link

The last version of MUI where it works as it should is @mui/material@5.15.10
Updating to 5.15.11 (or 5.15.20) introduces this ResizeObserver error, which is pretty annoying in development.
I cannot make any mentioned workaround work, so for now we are cementing in 5.15.10

There is nothing really too specific in our use case - standard MUI layout with Papers, Drawer, Tabs.

@DanielW093
Copy link

The last version of MUI where it works as it should is @mui/material@5.15.10 Updating to 5.15.11 (or 5.15.20) introduces this ResizeObserver error, which is pretty annoying in development. I cannot make any mentioned workaround work, so for now we are cementing in 5.15.10

There is nothing really too specific in our use case - standard MUI layout with Papers, Drawer, Tabs.

Interestingly enough, I still get the error in @mui/material@5.15.10 when using the multiline box in a tab. When refresh the page, it doesn't happen, but when I switch to a different MUI tab and then back to the one with the textbox, the error appears. Like you, there's nothing that strange about my use case. It's entirely standard MUI components.

@ZeeshanTamboli
Copy link
Member

Can someone provide live examples on CodeSandbox or StackBlitz? I can reproduce the issue with Joy UI Textarea (CodeSandbox) as shown here.

It would help if we get separate reproductions for Base UI TextareaAutosize and Material UI TextField with the multiline prop.

This issue was moved from the material-ui repo to this repository. The new Base UI repository includes new components available as the @base_ui/react package. I believe the TextareaAutosize in this package should not throw an error due to the change done in mui/base-ui#104 using requestAnimationFrame for the Resize Observer handler (as shown below).

However, for the Material UI TextField with the multiline prop, the legacy Base UI TextareaAutosize (used by Material UI <TextField multiline /> and Joy UI Textarea) and Joy UI Textarea, we need to fix it in the core repo as shown below:

--- a/packages/mui-base/src/TextareaAutosize/TextareaAutosize.tsx
+++ b/packages/mui-base/src/TextareaAutosize/TextareaAutosize.tsx
@@ -144,10 +144,7 @@ const TextareaAutosize = React.forwardRef(function TextareaAutosize(
     const handleResize = () => {
       syncHeight();
     };
-    // Workaround a "ResizeObserver loop completed with undelivered notifications" error
-    // in test.
-    // Note that we might need to use this logic in production per https://github.com/WICG/resize-observer/issues/38
-    // Also see https://github.com/mui/mui-x/issues/8733
+    // Workaround a "ResizeObserver loop completed with undelivered notifications" error.
     let rAF: any;
     const rAFHandleResize = () => {
       cancelAnimationFrame(rAF);
@@ -164,9 +161,7 @@ const TextareaAutosize = React.forwardRef(function TextareaAutosize(
     let resizeObserver: ResizeObserver;

     if (typeof ResizeObserver !== 'undefined') {
-      resizeObserver = new ResizeObserver(
-        process.env.NODE_ENV === 'test' ? rAFHandleResize : handleResize,
-      );
+      resizeObserver = new ResizeObserver(rAFHandleResize);
       resizeObserver.observe(input);
     }

I'm not entirely sure if this will fix the issue, so I'm requesting live reproductions first to test this change.

@DIPANKAR-123
Copy link

paolobiavati

Thanks buddy, this works as of now.

BenHunt17 referenced this issue in BenHunt17/pinboard-frontend Jul 6, 2024
Implemented api call to get real notes from api.

Implemented a useFetch hook to reuse.

Left a few TODOs as this took a while to get working and exceeded my time box

MUI seems to have an issue with the textField causing a resize observer error when multilines is used. https://github.com/mui/base-ui/issues/167

Downgraded mui to a version where this isn't an issue
@thehig
Copy link

thehig commented Jul 11, 2024

Oi, lost a day to tracking this down

@arshaan-abh
Copy link

Any updates on this issue?

@PasinduSenanayake
Copy link

This may not be the best solution and it won't solve the problem for everyone. But in my case this occurs when the width of the text field is less than 300px. (I didn't deep dive to find the root cause). So adding style={{minWidth:'300px'}} worked for me. It's not perfect, but as for the moment I'm happy with this hotfix as my implementation has a minWidth always greater than 300px.

@jacknkandy
Copy link

Having the same issue. Mine specifically is occurring when I have a TextField component with the multiline property enabled, being rendered in a Dialog on the initial page load. The issue wont occur if the dialog is opened after the page has loaded.

My workaround is as follows:

    const [multiline, setMultiline] = React.useState(false);

    React.useEffect(() => {
        setMultiline(true);
    }, []);

    render (
        <TextArea
            ...
            multiline={multiline}
        />
    );

So the text area is initially rendered without multiline, as soon as the component is mounted, the multiline property is toggled to true. This use case works for me, but understand it might not work for others.

@oliviertassinari oliviertassinari transferred this issue from mui/base-ui Sep 11, 2024
@oliviertassinari oliviertassinari added the component: TextareaAutosize The React component. label Sep 11, 2024
@madison-boman
Copy link

Any status on this?

@madison-boman
Copy link

Found a workaround using InputProps.

  <TextField
      InputProps={{
          rows: 18,
          multiline: true,
          inputComponent: 'textarea'
      }}
  />

This worked for me! Thanks!

@mnajdova
Copy link
Member

mnajdova commented Oct 2, 2024

Can anyone share a reproduction with Material UI? If you can't do it in CodeSandbox, feel free to create a GH repo with it. I tried it myself locally but I am not able to reproduce it.

@mnajdova mnajdova assigned mnajdova and unassigned mj12albert Oct 2, 2024
@johneriksson
Copy link

@mnajdova
CodeSandbox link. Sometimes the error is logged as soon as the page loads. Other times the error will appear when the width is changed in the useEffect.

@owlpro
Copy link

owlpro commented Oct 9, 2024

same issue
Is there a temporary solution?

@sipickles
Copy link

Found a workaround using InputProps.

  <TextField
      InputProps={{
          rows: 18,
          multiline: true,
          inputComponent: 'textarea'
      }}
  />

Best workaround I think. Thanks!

@MalyugaSensei
Copy link

This solution with the react-textarea-autosize library helped me:

import TextareaAutosize
// ...
InputProps={{
    multiline,
    inputComponent: TextareaAutosize,
}}

@mj12albert mj12albert self-assigned this Nov 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: TextareaAutosize The React component. priority: important This change can make a difference
Projects
None yet
Development

Successfully merging a pull request may close this issue.