feat: [#2375] add window.event legacy "current event" global during dispatch - #2376
Open
marciomazza wants to merge 1 commit into
Open
feat: [#2375] add window.event legacy "current event" global during dispatch#2376marciomazza wants to merge 1 commit into
window.event legacy "current event" global during dispatch#2376marciomazza wants to merge 1 commit into
Conversation
marciomazza
force-pushed
the
feat/window-event-global
branch
from
September 8, 2026 14:03
23a7b10 to
de9d464
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.
Description
Resolves #2375
window.eventis alwaysundefinedin happy-dom. Real browsers set it to the eventbeing dispatched for the duration of
dispatchEvent(), then restore the previous value —the HTML spec's "current event".
Libraries that still read it (e.g. React's
getCurrentEventPriority()) hit aTypeErrorwithout it.
Fix:
BrowserWindowgets aneventfield (defaultundefined, like idle browsers —not
null).EventTarget.dispatchEvent()saves the currentwindow.event, sets it tothe event, and restores it in a
finallyso a throwing listener can't leave it stale.Two spec deviations left on purpose:
window.eventis set once around the whole dispatchrather than per listener invocation, and listeners in a shadow tree
(
invocationTargetInShadowTree) are not excluded from seeing it.Tests
Added 3 tests:
window.eventis the event during dispatch andundefinedagain after;a nested
dispatchEvent()restores the outer event on return; a throwing listener stillrestores it. Full
npm testpasses (303 files / 7804 tests).Before submitting the PR, please make sure you do the following:
Tests
window.eventmatches the new tests (idleundefined, the event during dispatch, restored on nested-dispatch return, restored after a throw).npm testlocally to make sure that all tests pass before submitting the PR.Title
feat,fix,choreorBREAKING CHANGE. The issue is optional and can be omitted if the pull request does not relate to an issue.AI
I used Claude Code to write this, over multiple iterations. I guided and reviewed
it myself at every step.