reactjserror-handlingmaterial-uieslintresize-observer

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,GRAD@20..48,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.


Solution

  • 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');
                }
            }
        });
    }, []);