Ash*_*man 17 error-handling reactjs eslint material-ui resize-observer
最近,我的 React 应用程序中开始出现一个新错误:
ResizeObserver loop limit exceeded
似乎普遍的共识是该错误是良性的,没有什么可担心的。
但是,当我通过 测试我的程序时,我不确定如何忽略它或让它停止显示npm start
。
出现的屏幕如下所示:
有什么方法可以抑制此页面或其他地方的此特定错误,这样我就不必每次都将其忽略?
该错误来自我使用的MUI Masonry 组件,但我的理解是它可能来自许多依赖项。
这是我使用它的代码,以防有助于抑制此错误。
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>
);
}
Run Code Online (Sandbox Code Playgroud)
我尝试更新我的依赖项,看看是否有其他人在 github 上遇到过这个问题,但我找不到任何东西。如果有我可以尝试的解决方案,请告诉我,我看到可以编辑 ESLINT 配置,但我真的想避免弹出我的 create-react-app。
san*_*ooh 16
react-virtuoso
我遇到了同样的问题,但在将 webpack 版本更新到 5.xx 后出现了虚拟化列表( https://github.com/petyosi/react-virtuoso/issues/254)。根据 Hai Nguyen Le ( /sf/answers/5327549531/ ) 的答案,我创建了一个更简单的版本,仅捕获 ResizeObserver 错误:
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');
}
}
});
}, []);
Run Code Online (Sandbox Code Playgroud)
小智 8
您可以将 webpack 配置为不显示此错误的覆盖图。为此,您可以在字段“client”内添加配置,该字段位于“devServer”字段内,如下:
overlay: {
runtimeErrors: (error) => {
if (error.message === 'ResizeObserver loop limit exceeded') {
return false;
}
return true;
},
},
Run Code Online (Sandbox Code Playgroud)
这是有关它的文档: https: //webpack.js.org/configuration/dev-server/#overlay。
遇到了同样的问题,最终是由于 Masonry 组件内的第一个元素具有 100% 宽度,一旦我删除了它(实际上使其在 XS 下响应为 100% - 没有问题..),问题就停止了..
归档时间: |
|
查看次数: |
28281 次 |
最近记录: |