Ashar Rahman
Ashar Rahman

Reputation: 325

How to stop 'ResizeObserver loop limit exceeded' error from appearing in React app

Recently, a new error started showing in my React application:

ResizeObserver loop limit exceeded

Seems that the general consensus is that the error is benign and there is nothing to worry about.

However, I am not sure how to ignore it or to get it to stop showing up when I am testing my program via npm start.

The screen that appears looks like this:

enter image description here

Is there any way to suppress this particular errror on this page or otherwise so I don't have to dismiss it every time?

The error comes from the MUI Masonry component i use but my understanding is it can come from many dependencies.

Here is the code in which I use it incase that helps in supressing this error.

import Masonry from '@mui/lab/Masonry';
import { Box } from '@mui/material';
import { ReactNode } from 'react';
import { BsFillPlusSquareFill as AddButton } from 'react-icons/bs';
import { useNavigate } from 'react-router';
import { LoadingIndicator } from '../LoadingIndicator';
import { BackButton } from './BackButton';
import styles from './SheskaList.module.css';

export const SheskaListContent = (props: { loading: boolean, cards: ReactNode[] }) => {
    const navigate = useNavigate();

    return (
        <Box className={styles.gridContainer}>
            <link rel='stylesheet' href='https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,[email protected],100..700,0..1,-50..200' />
            <div className={styles.pageTitleContainer}>
                <h1 className={styles.pageTitle}> Your Sheska List </h1>
                <AddButton size={'3em'} className={styles.addCardButton} onClick={() => {navigate('/newitem')}} />
            </div>
            <Masonry columns={{lg: 2, xs: 1}} spacing={3} id={styles.grid}>
                {
                    props.loading
                    ?
                    <LoadingIndicator />
                    :
                    props.cards[0] as NonNullable<ReactNode>
                }
                <BackButton key='back-button' location='/dashboard' text='Return to Home' />
                {
                    !props.loading
                    &&
                    props.cards.slice(1)
                }
            </Masonry>
        </Box>
    );
}

I have tried updating my dependencies and seeing if anybody else has had this issue on github but I could not find anything. Please let me know if there are any solutions i can try, I saw that it is possible to edit ESLINT configs but I really want to avoid ejecting my create-react-app.

Upvotes: 19

Views: 43086

Answers (9)

Zia ul Qamar
Zia ul Qamar

Reputation: 13

Issue solved when I am trying to make a time picker using fluent UI React in Field because I facing an error below

ResizeObserver loop completed with undelivered notifications

when I removed Field from side to time picker my issue is solved

before

   <Field label="Start Time">
    <TimePicker />
  </Field>

after

 <TimePicker onTimeChange={timechange} />

if you have face this issue you can try this one may be it will work for you

Upvotes: 0

Nikita Petrov
Nikita Petrov

Reputation: 136

You can configure webpack not to show overlay on this error. To do this you can add in config inside field: "client", which is inside field "devServer", this:

    overlay: {
      runtimeErrors: (error) => {
        if (error.message === 'ResizeObserver loop limit exceeded') {
          return false;
        }

        return true;
      },
    },

Here's the docs about it: https://webpack.js.org/configuration/dev-server/#overlay .

Upvotes: 10

Ben in CA
Ben in CA

Reputation: 851

If you're running AG Grid (as I am)...

This was a bug in v29.X that was logged as AG-8567 Grid shows error ResizeObserver loop limit exceeded

You can see this in the changelog: https://ag-grid.com/changelog/?searchQuery=8567

This issue is now fixed in AG Grid v30 and later.

Upvotes: 2

user21784620
user21784620

Reputation: 11

I was getting this error because in calling function , was calling the endpoint before state update.

Fix : After updating the state , calling the endpoint

Upvotes: 1

Nitin .
Nitin .

Reputation: 848

<script>
   window.addEventListener('error', function (e) {
    console.error(e.message);
       // prevent React's listener from firing
    e.stopImmediatePropagation();
      // prevent the browser's console error message
    e.preventDefault();
 });

Add this code to your index file and see result !

Upvotes: -1

behruz
behruz

Reputation: 588

I was getting this error because I was misusing the onFirstDataRenderered of ag-grid. This error may occur if you use onFirstDataRendered to call the sizeColumnsToFit method. Instead, you should use onGridReady

Upvotes: 1

sanyooh
sanyooh

Reputation: 1631

I had the same issue but with a virtualized list from react-virtuoso after updating webpack version to 5.x.x (https://github.com/petyosi/react-virtuoso/issues/254). based on the answer from Hai Nguyen Le (https://stackoverflow.com/a/76107850/3328233) I created a simpler version of it to only catch the ResizeObserver error:

    useEffect(() => {
    window.addEventListener('error', e => {
        if (e.message === 'ResizeObserver loop limit exceeded') {
            const resizeObserverErrDiv = document.getElementById(
                'webpack-dev-server-client-overlay-div'
            );
            const resizeObserverErr = document.getElementById(
                'webpack-dev-server-client-overlay'
            );
            if (resizeObserverErr) {
                resizeObserverErr.setAttribute('style', 'display: none');
            }
            if (resizeObserverErrDiv) {
                resizeObserverErrDiv.setAttribute('style', 'display: none');
            }
        }
    });
}, []);

Upvotes: 19

Hai Nguyen Le
Hai Nguyen Le

Reputation: 111

In your React App, push this code:

    useBeforeRender(() => {
    window.addEventListener("error", (e) => {
      if (e) {
        const resizeObserverErrDiv = document.getElementById(
          "webpack-dev-server-client-overlay-div",
        );
        const resizeObserverErr = document.getElementById(
          "webpack-dev-server-client-overlay",
        );
        if (resizeObserverErr)
          resizeObserverErr.className = "hide-resize-observer";
        if (resizeObserverErrDiv)
          resizeObserverErrDiv.className = "hide-resize-observer";
      }
    });
  }, []);

and create hooks: useBeforeRender

import { useEffect, useState } from "react";

export const useBeforeRender = (callback: any, deps: any) => {
  const [isRun, setIsRun] = useState(false);

  if (!isRun) {
    callback();
    setIsRun(true);
  }

  useEffect(() => () => setIsRun(false), deps);
};

use this in .scss or .css file:

.hide-resize-observer {
  display: none !important;
}

Upvotes: 2

Roman
Roman

Reputation: 2025

Had the same issue, it ended up to be due to the first element inside the Masonry component having 100% width, once I removed that (actually made it responsive under XS to be 100% - where it had no issue..) issue stopped..

Upvotes: 5

Related Questions