Skip to content

perf(reporter): tear down Scroller scroll listener on reset and reassignment#33607

Merged
jennifer-shehane merged 10 commits into
developfrom
remove-scroller-scroll-listener
Apr 22, 2026
Merged

perf(reporter): tear down Scroller scroll listener on reset and reassignment#33607
jennifer-shehane merged 10 commits into
developfrom
remove-scroller-scroll-listener

Conversation

@jennifer-shehane
Copy link
Copy Markdown
Member

@jennifer-shehane jennifer-shehane commented Apr 14, 2026

Additional details

Each setContainer previously registered another anonymous scroll listener with no matching removal, so listener count grew with container reassignment.

  • Stop stacking scroll listeners when setContainer runs more than once (or after __reset + setContainer) by pairing addEventListener / removeEventListener with a single stable handler.
  • Unsubscribe from the current container before nulling it so tests and teardown do not leak handlers on the DOM node.

Note

Medium Risk
Touches core reporter scrolling event wiring; risk is mostly around missed/duplicate listener attachment in edge cases or older environments without AbortController/removeEventListener, but the change is small and covered by updated unit tests.

Overview
Fixes a performance issue in the reporter where calling scroller.setContainer() multiple times could stack scroll event listeners on the same DOM node.

Scroller now uses a stable _onContainerScroll handler and explicitly detaches any existing listener (via removeEventListener and an AbortController) before reattaching, and also detaches on __reset() to avoid leaks during teardown. Tests were updated to model removeEventListener, add coverage for repeated setContainer calls, and changelog notes the scrolling overhead reduction in cypress open.

Reviewed by Cursor Bugbot for commit 1941da8. Bugbot is set up for automated code reviews on this repo. Configure here.

Steps to test

cd packages/reporter
yarn check-ts
yarn lint -- src/lib/scroller.ts cypress/e2e/unit/scroller.cy.ts
yarn cypress:run:ct --spec cypress/e2e/unit/scroller.cy.ts

How has the user experience changed?

Improved performance when scrolling in reporter

PR Tasks

…ignment

setContainer and __reset could leave multiple scroll handlers on the same
container because each setContainer added a new anonymous listener and
never called removeEventListener.
Use a stable handler plus _listenToScrolls / _stopListeningToScrolls so the
previous node is always unsubscribed before attaching to a new container,
and __reset unsubscribes before clearing state.
Add a unit test for repeated setContainer and extend the test container type
so removeEventListener is typed as a Sinon spy.
@jennifer-shehane jennifer-shehane self-assigned this Apr 14, 2026
@cypress
Copy link
Copy Markdown

cypress Bot commented Apr 14, 2026

cypress    Run #70127

Run Properties:  status check passed Passed #70127  •  git commit 1941da8b4b: Merge branch 'develop' into remove-scroller-scroll-listener
Project cypress
Branch Review remove-scroller-scroll-listener
Run status status check passed Passed #70127
Run duration 16m 20s
Commit git commit 1941da8b4b: Merge branch 'develop' into remove-scroller-scroll-listener
Committer Jennifer Shehane
View all properties for this run ↗︎

Test results
Tests that failed  Failures 0
Tests that were flaky  Flaky 1
Tests that did not run due to a developer annotating a test with .skip  Pending 10
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 658
View all changes introduced in this branch ↗︎
UI Coverage  0%
  Untested elements 4  
  Tested elements 0  
Accessibility  100%
  Failed rules  0 critical   0 serious   0 moderate   0 minor
  Failed elements 0  

@jennifer-shehane jennifer-shehane merged commit 40eccdb into develop Apr 22, 2026
92 of 94 checks passed
@jennifer-shehane jennifer-shehane deleted the remove-scroller-scroll-listener branch April 22, 2026 15:57
@cypress-bot
Copy link
Copy Markdown
Contributor

cypress-bot Bot commented Apr 29, 2026

Released in 15.14.2.

This comment thread has been locked. If you are still experiencing this issue after upgrading to
Cypress v15.14.2, please open a new issue.

@cypress-bot cypress-bot Bot locked as resolved and limited conversation to collaborators Apr 29, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants