Skip to content

Fix/cypress resizeobserver mock#11193

Closed
AarishMansur wants to merge 3 commits intomarmelab:nextfrom
AarishMansur:fix/cypress-resizeobserver-mock
Closed

Fix/cypress resizeobserver mock#11193
AarishMansur wants to merge 3 commits intomarmelab:nextfrom
AarishMansur:fix/cypress-resizeobserver-mock

Conversation

@AarishMansur
Copy link
Contributor

Problem

Cypress tests trigger the browser error:

ResizeObserver loop completed with undelivered notifications

This happens when components using ResizeObserver cause repeated resize cycles in the Cypress environment.

The current workaround suppresses this error using Cypress.on('uncaught:exception'). While this prevents test failures, it hides real issues and reduces the reliability of the test suite.

Solution

Replaced the error suppression workaround with a proper ResizeObserver mock.

  • Added a dedicated ResizeObserverMock utility that:

    • Implements the full ResizeObserver interface (observe, unobserve, disconnect)
    • Triggers callbacks asynchronously using requestAnimationFrame to avoid loops
    • Provides realistic contentRect values via getBoundingClientRect
    • Responds to window resize events to support responsive components
  • Injected the mock using Cypress.on('window:before:load') so it is available before the application initializes

  • Removed the uncaught:exception handler that was previously ignoring the error

  • Updated Cypress TypeScript configuration to properly support .js files and prevent emit conflicts

This ensures stable test execution while keeping error reporting accurate.

How To Test

  1. Run Cypress tests:

    yarn cypress run --spec cypress/e2e/list.cy.js
  2. Verify:

  • All tests pass successfully
  • No ResizeObserver loop completed... errors appear
  • No uncaught:exception suppression is present

Additional Checks

  • The PR targets master for a bugfix or a documentation fix, or next for a feature
  • The PR includes unit tests (not applicable this change affects test infrastructure only)
  • The PR includes one or several stories (not applicable no UI changes)
  • The documentation is up to date

Fixes : #10649

@AarishMansur AarishMansur force-pushed the fix/cypress-resizeobserver-mock branch from 54e66ab to 03da508 Compare March 18, 2026 16:13
@slax57 slax57 requested review from Copilot and slax57 March 19, 2026 09:16
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves Cypress test stability by replacing the current suppression of the ResizeObserver loop completed with undelivered notifications error with a dedicated ResizeObserver mock injected before the AUT initializes.

Changes:

  • Add a ResizeObserverMock implementation for Cypress runs.
  • Inject the mock via Cypress.on('window:before:load') and remove the prior uncaught:exception suppression workaround.
  • Update Cypress TypeScript configuration to include JS files and avoid emitting.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
cypress/tsconfig.json Expands TS project scope for Cypress files and disables emit.
cypress/support/index.js Injects the ResizeObserver mock into the AUT window before load.
cypress/support/ResizeObserverMock.js Implements a basic ResizeObserver mock and triggers callbacks asynchronously.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +8 to +21
observe(element) {
this.elements.add(element);
this.trigger();
window.addEventListener('resize', this.handleResize);
}

unobserve(element) {
this.elements.delete(element);
}

disconnect() {
this.elements.clear();
window.removeEventListener('resize', this.handleResize);
}
Comment on lines +2 to +10
"extends": "../tsconfig.json",
"compilerOptions": {
"rootDir": "e2e"
"rootDir": ".",
"noEmit": true
},
"types": ["cypress", "node"]
}
"types": [
"cypress",
"node"
],
Comment on lines +8 to +36
observe(element) {
this.elements.add(element);
this.trigger();
window.addEventListener('resize', this.handleResize);
}

unobserve(element) {
this.elements.delete(element);
}

disconnect() {
this.elements.clear();
window.removeEventListener('resize', this.handleResize);
}

handleResize() {
this.trigger();
}

trigger() {
if (this.elements.size === 0) return;

const entries = Array.from(this.elements).map(e => ({
target: e,
contentRect: e.getBoundingClientRect(),
}));

requestAnimationFrame(() => {
this.callback(entries, this);
Copy link
Contributor

@slax57 slax57 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AarishMansur Thanks for the PR.

Before reviewing, I first tried to see if I could reproduce the issue (without your fix, i.e. by staying on master and commenting out the content of the cypress/support/index.js file), but couldn't.

Are you able to reproduce the issue on master? If so, can you provide detailed test instructions? What browser are you using? (I tried with electron)
Also, where are the errors supposed to appear: in the terminal or the DevTools console?

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants