Skip to content

Commit

Permalink
fix(polyfill): dedupe hooks.addEventListener calls (#406)
Browse files Browse the repository at this point in the history
* fix(polyfill): dont call hooks.addEventListener when rejecting duplicate listeners in EventTarget.addEventListener

* Add changeset

---------

Co-authored-by: Chris Sauve <chris.sauve@shopify.com>
  • Loading branch information
developit and lemonmade authored Aug 9, 2024
1 parent a892e66 commit 2ea3459
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/loud-steaks-argue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@remote-dom/polyfill': patch
---

Fixes `hooks.addEventListener()` being called even when `EventTarget.addEventListener()` rejects a duplicate listener registration
3 changes: 2 additions & 1 deletion packages/polyfill/source/EventTarget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class EventTarget {
listeners.set(key, list);
}

list.add(normalizedListener);
if (list.has(normalizedListener)) return;

signal?.addEventListener(
'abort',
Expand All @@ -66,6 +66,7 @@ export class EventTarget {
{once: true},
);

list.add(normalizedListener);
hooks.addEventListener?.(this as any, type, listener, options);
}

Expand Down

0 comments on commit 2ea3459

Please sign in to comment.