perf(reporter): tear down Scroller scroll listener on reset and reassignment#33607
Merged
Conversation
…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.
cypress
|
||||||||||||||||||||||||||||||||||||||||
| Project |
cypress
|
| Branch Review |
remove-scroller-scroll-listener
|
| Run status |
|
| Run duration | 16m 20s |
| Commit |
|
| Committer | Jennifer Shehane |
| View all properties for this run ↗︎ | |
| Test results | |
|---|---|
|
|
0
|
|
|
1
|
|
|
10
|
|
|
0
|
|
|
658
|
| View all changes introduced in this branch ↗︎ | |
UI Coverage
0%
|
|
|---|---|
|
|
4
|
|
|
0
|
Accessibility
100%
|
|
|---|---|
|
|
0 critical
0 serious
0 moderate
0 minor
|
|
|
0
|
cacieprins
approved these changes
Apr 22, 2026
Contributor
|
Released in This comment thread has been locked. If you are still experiencing this issue after upgrading to |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Additional details
Each
setContainerpreviously registered another anonymousscrolllistener with no matching removal, so listener count grew with container reassignment.scrolllisteners whensetContainerruns more than once (or after__reset+setContainer) by pairingaddEventListener/removeEventListenerwith a single stable handler.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 stackscrollevent listeners on the same DOM node.Scrollernow uses a stable_onContainerScrollhandler and explicitly detaches any existing listener (viaremoveEventListenerand anAbortController) before reattaching, and also detaches on__reset()to avoid leaks during teardown. Tests were updated to modelremoveEventListener, add coverage for repeatedsetContainercalls, and changelog notes the scrolling overhead reduction incypress 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.tsHow has the user experience changed?
Improved performance when scrolling in reporter
PR Tasks
cypress-documentation?type definitions?