Skip to content

fix: [#2089] Make removeEventListener respect the capture parameter#2133

Open
coffeeandwork wants to merge 1 commit intocapricorn86:masterfrom
coffeeandwork:fix/2089-removeeventlistener-capture
Open

fix: [#2089] Make removeEventListener respect the capture parameter#2133
coffeeandwork wants to merge 1 commit intocapricorn86:masterfrom
coffeeandwork:fix/2089-removeeventlistener-capture

Conversation

@coffeeandwork
Copy link
Copy Markdown
Contributor

@coffeeandwork coffeeandwork commented Apr 13, 2026

removeEventListener was ignoring its third argument, so it couldn't distinguish between capture and non-capture listeners. Calling removeEventListener('click', cb, false) would happily remove a listener that was added with addEventListener('click', cb, true), which isn't how the DOM spec works.

The once auto-removal and signal abort cleanup had the same problem — neither forwarded the capture flag, so they could end up removing the wrong listener if the same callback was registered in both phases.

While fixing this I also noticed Document.open() was iterating capturing listeners but calling removeEventListener without { capture: true }, so those listeners were silently surviving the clear.

Fixes #2089

Testing

Added tests for capture-aware removal (boolean and options object), default-to-bubbling behavior, once/signal phase isolation, DOM element parent-child propagation, and Document.open() clearing both phases. All existing tests still pass.

@coffeeandwork coffeeandwork force-pushed the fix/2089-removeeventlistener-capture branch from 91716c3 to 35db451 Compare April 13, 2026 16:12
…parameter

The third argument to removeEventListener was missing, so it couldn't
tell capture and non-capture listeners apart. This also broke the
once auto-removal and signal abort paths since neither forwarded the
capture flag.

Also fixed a bug in Document.open() where capturing listeners weren't
actually being removed because the capture flag wasn't being passed.
@coffeeandwork coffeeandwork force-pushed the fix/2089-removeeventlistener-capture branch from 35db451 to 725d6a1 Compare April 13, 2026 16:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

removeEventListener ignores the capture parameter

2 participants