Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test coverage for event listener leaking #455

Merged
merged 3 commits into from
Nov 19, 2021

Conversation

seanpdoyle
Copy link
Contributor

Add test coverage for event listener leaking

Add test coverage to hotwired/turbo#454. While the original fix was
important to ship, it was unclear how to guard against re-introducing
the leaks.

This commit introduces the withoutChangingEventListenersCount() test
helper to wrap a block within the test harness. While executing within
the block, the driven page's document.addEventListener and
document.removeEventListener functions are replaced with decorated
functions that increment and decrement a counter. At the start of the
block, capture and return how many times addEventListener has been
invoked without a matching removeEventListener. At the end, capture
and return the differential.

Move the disconnectedCallback() call

The fix introduced in hotwired/turbo#454 resolved the issue, but
introduced a matching disconnectedCallback() far-off in the
FrameRenderer.

This commit moves that call to occur immediately after it's paired
element.connectedCallback().

Add test coverage to [hotwired#454][]. While the original fix was
important to ship, it was unclear how to guard against re-introducing
the leaks.

This commit introduces the `withoutChangingEventListenersCount()` test
helper to wrap a block within the test harness. While executing within
the block, the driven page's `document.addEventListener` and
`document.removeEventListener` functions are replaced with decorated
functions that increment and decrement a counter. At the start of the
block, capture and return how many times `addEventListener` has been
invoked without a matching `removeEventListener`. At the end, capture
and return the differential.

[hotwired#454]: hotwired#454
@seanpdoyle seanpdoyle force-pushed the event-listener-leak-test-coverage branch from 7cae7cd to 6269715 Compare November 18, 2021 21:07
The fix introduced in [hotwired#454][] resolved the issue, but
introduced a matching `disconnectedCallback()` far-off in the
`FrameRenderer`.

This commit moves that call to occur _immediately_ after it's paired
`element.connectedCallback()`.

[hotwired#454]: hotwired#454
@seanpdoyle seanpdoyle force-pushed the event-listener-leak-test-coverage branch from 6269715 to 9d38683 Compare November 18, 2021 21:11
@dhh dhh merged commit 8266575 into hotwired:main Nov 19, 2021
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.

2 participants