fix: [#2089] Make removeEventListener respect the capture parameter#2133
Open
coffeeandwork wants to merge 1 commit intocapricorn86:masterfrom
Open
fix: [#2089] Make removeEventListener respect the capture parameter#2133coffeeandwork wants to merge 1 commit intocapricorn86:masterfrom
coffeeandwork wants to merge 1 commit intocapricorn86:masterfrom
Conversation
91716c3 to
35db451
Compare
…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.
35db451 to
725d6a1
Compare
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
removeEventListenerwas ignoring its third argument, so it couldn't distinguish between capture and non-capture listeners. CallingremoveEventListener('click', cb, false)would happily remove a listener that was added withaddEventListener('click', cb, true), which isn't how the DOM spec works.The
onceauto-removal andsignalabort 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 callingremoveEventListenerwithout{ 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/signalphase isolation, DOM element parent-child propagation, andDocument.open()clearing both phases. All existing tests still pass.