Repository navigation
Conversation
EventTarget.prototype[kHybridDispatch] cleared kIsBeingDispatched inside the listener loop right after the first listener, even though it is already cleared after the loop finishes. Subsequent listeners observed event.currentTarget === null, event.eventPhase === Event.NONE, an empty composedPath(), and could recursively dispatch the same event. Remove the premature reset inside the dispatch loop and wrap the loop in try/finally so kIsBeingDispatched is always cleared after dispatch even if a once-listener removal hook throws. As a result, re-dispatching the same event synchronously from a second or later listener now throws ERR_EVENT_RECURSION, matching the first listener and the DOM spec. Signed-off-by: Yaroslav Chuhai <yaroslavchuhai@gmail.com>
ychuhai
force-pushed
the
fix/eventtarget-dispatch-state
branch
from
November 24, 2026 23:22
7a62d29 to
e9dbee5
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #67765 +/- ##
==========================================
+ Coverage 90.52% 90.56% +0.03%
==========================================
Files 803 803
Lines 285057 285201 +144
Branches 55016 55057 +41
==========================================
+ Hits 258062 258289 +227
+ Misses 17148 17070 -78
+ Partials 9847 9842 -5
🚀 New features to boost your workflow:
|
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.
EventTarget.prototype[kHybridDispatch]setsevent[kIsBeingDispatched] = truebefore the listener loop and clears it after the loop finishes, but it also clearedarg[kIsBeingDispatched] = falseinside the loop right after invoking each listener.As a result, only the first listener saw the event as being dispatched. Any second or later listener observed
event.currentTarget === null,event.eventPhase === Event.NONE(0), an emptyevent.composedPath(), and could mutate the event withinitEvent()or re-dispatch it withoutERR_EVENT_RECURSION:This removes the premature reset inside the loop and wraps the loop in
try/finallysokIsBeingDispatchedis always cleared when dispatch exits, even if aonce-listener removal hook ([kRemoveListener]) throws.Note (
semver-major): re-dispatching the same event synchronously or callinginitEvent()from a second or later listener now throwsERR_EVENT_RECURSIONor is ignored, respectively, matching the first listener and the WHATWG DOM spec.Refs: https://dom.spec.whatwg.org/#concept-event-dispatch