Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages
Next.js and React

Cypress fails on ResizeObserver loop completed with undelivered notifications

Your error

ResizeObserver loop completed with undelivered notifications.1 more line it can show

Fix it fast

Most common cause, 1 of 2

The observer callback keeps resizing the element it watches

Move the size change into requestAnimationFrame so it runs after paint, and keep a record of the size you set so the callback does nothing when the element already has it.

Fix
const expected = new WeakMap();
const ro = new ResizeObserver((entries) => {
  requestAnimationFrame(() => {
    for (const entry of entries) {
      const want = Math.round(entry.contentBoxSize[0].inlineSize);
      if (expected.get(entry.target) === want) continue;
      expected.set(entry.target, want);
      entry.target.style.height = `${want / 2}px`;
    }
  });
});
ro.observe(document.querySelector('.panel'));
Did this fix it?
Full steps for this cause: check, fix, verify

Short answer

ResizeObserver loop completed with undelivered notifications is a window error event the browser fires when a ResizeObserver callback changes layout and some resize notifications must wait for the next frame. Cypress fails the test on it. If it repeats every frame, defer the resize in requestAnimationFrame; if it fires once, ignore only that message in an uncaught:exception handler (Cypress 16).

  • Applies to Cypress 16.3, Chrome, Edge and Firefox (current releases)
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Which cause do you have?

Open the page in a normal browser tab, paste the listener below into the DevTools console, then resize the window and use the screen the test covers. A counter that climbs on every frame means a real loop (cause 1). One or two hits that then stop mean a layout that settles by itself (cause 2).

Run this first
let hits = 0;
window.addEventListener('error', (e) => {
  if (e.message.includes('ResizeObserver loop')) console.log('ResizeObserver loop', ++hits);
});

Then find the line you see in this list and open its fix:

  1. 1The observer callback keeps resizing the element it watchesThe counter rises without stopping, and the element visibly grows, shrinks or flickers
  2. 2A one-off notice from a library makes Cypress fail the testThe counter shows a hit or two during load, the layout looks right, and only the Cypress run turns red

What does the error look like?

  • ResizeObserver loop completed with undelivered notifications.
  • Error: ResizeObserver loop completed with undelivered notifications.

Cause 1 of 2

The observer callback keeps resizing the element it watches

You seeThe counter rises without stopping, and the element visibly grows, shrinks or flickers

Check

The ResizeObserver loop message is the browser protecting itself. Each callback that changes a size forces layout to run again, notifications for shallower elements are pushed to the next frame, and an error event lands on window. Code that sets width or height on its own target inside the callback starts that cycle again every frame.

Check
grep -rn "new ResizeObserver" src

Fix

Move the size change into requestAnimationFrame so it runs after paint, and keep a record of the size you set so the callback does nothing when the element already has it.

Fix
const expected = new WeakMap();
const ro = new ResizeObserver((entries) => {
  requestAnimationFrame(() => {
    for (const entry of entries) {
      const want = Math.round(entry.contentBoxSize[0].inlineSize);
      if (expected.get(entry.target) === want) continue;
      expected.set(entry.target, want);
      entry.target.style.height = `${want / 2}px`;
    }
  });
});
ro.observe(document.querySelector('.panel'));

Verify

Run the console listener again and resize the window. The counter stays at zero and the element keeps a steady size.

Verify
npx cypress run --spec "cypress/e2e/panel.cy.js"

Confirmed by developer.mozilla.org

Did this fix it?

Cause 2 of 2

A one-off notice from a library makes Cypress fail the test

You seeThe counter shows a hit or two during load, the layout looks right, and only the Cypress run turns red

Check

Layout code inside a component, for example a chart or grid, may change a size once while it mounts. That gives a single ResizeObserver loop event, and the layout settles on the following frame. Cypress fails any test when the app under test raises an uncaught exception, so this harmless event stops the run.

Check
grep -rn "uncaught:exception" cypress/support

Fix

In the support file (cypress/support/e2e.js by default), which loads before the spec files, return false for this one message only. Every other app error still fails the test.

Fix
// cypress/support/e2e.js
Cypress.on('uncaught:exception', (err) => {
  if (err.message.includes('ResizeObserver loop completed with undelivered notifications')) {
    return false;
  }
});

Verify

The spec passes, and an unrelated error thrown on purpose in the app still fails it.

Verify
npx cypress run

Confirmed by docs.cypress.io

Did this fix it?

How do I stop it coming back?

  • Review every new ResizeObserver callback for writes to the size of the element it observes, and require requestAnimationFrame around them.
  • Keep the Cypress filter matched on the full message text; a handler that returns false for every error hides real crashes.
  • Run the console counter once after adding or upgrading a chart, editor or virtual-list library.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.