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

Enforce removal of events on addEventListener #235

Open
fregante opened this issue Mar 4, 2024 · 0 comments
Open

Enforce removal of events on addEventListener #235

fregante opened this issue Mar 4, 2024 · 0 comments

Comments

@fregante
Copy link
Collaborator

fregante commented Mar 4, 2024

Every addEventListener must be followed by a removeEventListener or else they'll be left behind and cause hard-to-debug issues:

Enforcing removeEventListener might be difficult, but requiring a signal could be done via types. For example:

addEventListener(
	type: string,
	listener: EventListenerOrEventListenerObject,
-	options?: boolean | AddEventListenerOptions
+	options: AddEventListenerOptions & {signal: AbortSignal}
): void;

Or just via no-restricted-syntax.


The most recent issue I found was this listener, left behind between reloads:

https://github.com/pixiebrix/pixiebrix-extension/blob/4878e51b4466cf6d628b5085c6ac964510a924f4/src/contentScript/selectionTooltip/tooltipController.tsx#L281-L299

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

No branches or pull requests

2 participants