【Bug】ERROR ResizeObserver loop completed with undelivered notifications.

简介: 【Bug】ERROR ResizeObserver loop completed with undelivered notifications.

报错如下:

ERROR
ResizeObserver loop completed with undelivered notifications.
    at handleError (webpack-internal:///./node_modules/webpack-dev-server/client/overlay.js:299:58)
    at eval (webpack-internal:///./node_modules/webpack-dev-server/client/overlay.js:318:7)

报错的原因:在页面绘制的时候,页面突然发生调整大小的事件,导致了样式和布局都需要重新评估,这个调整大小导致的布局变化,将延迟到下一帧来绘制。

解决方案:

在App.vue文件中添加以下代码:

<script >
// 解决ERROR ResizeObserver loop completed with undelivered notifications.
//问题的
const debounce = (fn, delay) => {
  let timer = null;
  return function () {
    let context = this;
    let args = arguments;
    clearTimeout(timer);
    timer = setTimeout(function () {
      fn.apply(context, args);
    }, delay);
  };
};
// 解决ERROR ResizeObserver loop completed with undelivered notifications.
const _ResizeObserver = window.ResizeObserver;
window.ResizeObserver = class ResizeObserver extends _ResizeObserver {
  constructor(callback) {
    callback = debounce(callback, 16);
    super(callback);
  }
};
</script>

下面是对这个代码的解释:

首先,debounce函数用于限制一个函数的执行频率,确保在一定时间间隔内只执行一次。它接受两个参数,一个是要执行的函数fn,另一个是延迟时间delay。函数内部使用setTimeout来实现延迟执行,每次调用时会清除之前的定时器,然后设置一个新的定时器来延迟执行目标函数。

接下来,代码对window.ResizeObserver进行了扩展。它将原始的ResizeObserver保存为_ResizeObserver,然后定义了一个新的ResizeObserver类,重写了其构造函数。在新的构造函数中,传入的回调函数被用debounce函数处理,确保回调函数在16毫秒的间隔内执行一次。这样做是为了限制ResizeObserver的回调频率,以避免过多的触发,提高性能。

这段代码实现了对ResizeObserver的改写,通过限制回调函数的执行频率来优化性能。

通过调整回调频率能解决上面讲解的问题报错原因。


相关文章
|
7月前
|
JavaScript 前端开发
【报错】unhandled error during execution of watcher callback
JavaScript错误`unhandled error during execution of watcher callback`在Echarts图表渲染时出现,通常是因数据未获取到就尝试渲染导致。解决方法是在渲染前添加非空判断,如`if(value){开始渲染数据}`或`if(value !== undefined){开始渲染数据}`,确保数据加载完成后再执行渲染。
879 0
ResizeObserver loop completed with undelivered notifications
ResizeObserver loop completed with undelivered notifications
|
6月前
|
Python
【ERROR】asyncio.run(main())报错:RuntimeError: Event loop is closed
【ERROR】asyncio.run(main())报错:RuntimeError: Event loop is closed
173 0
|
数据库 数据库管理
【异常解决】svn报“Previous operation has not finished; run ‘cleanup‘ if it was interrupted”的错误解决方案
【异常解决】svn报“Previous operation has not finished; run ‘cleanup‘ if it was interrupted”的错误解决方案
615 0
|
前端开发
The following tasks did not complete: first Did you forget to signal async completion?
The following tasks did not complete: first Did you forget to signal async completion?
|
数据安全/隐私保护
Do Sync Disk 0 Part 0 Failed, code=S3_F42, msg=Sync Failed after retry 5 times
Do Sync Disk 0 Part 0 Failed, code=S3_F42, msg=Sync Failed after retry 5 times
199 1
|
Java Spring
Redisson BUG: Failed to submit a listener notification task. Event loop shut down?
Redisson BUG: Failed to submit a listener notification task. Event loop shut down?
1444 0
Error:svn:E155037:Previous operation has not finished; run ‘cleanup‘ if it was interrupted(完美解决)
Error:svn:E155037:Previous operation has not finished; run ‘cleanup‘ if it was interrupted(完美解决)
429 0
Error:svn:E155037:Previous operation has not finished; run ‘cleanup‘ if it was interrupted(完美解决)
TortoiseSVN报错:“Previous operation has not finished; run 'clean up' if it was interrupted“ 的解决方法
TortoiseSVN报错:“Previous operation has not finished; run 'clean up' if it was interrupted“ 的解决方法
349 0
TortoiseSVN报错:“Previous operation has not finished; run 'clean up' if it was interrupted“ 的解决方法

热门文章

最新文章