Skip to content

Correctly handle the event.currentTarget property #4559

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

jasnell
Copy link
Collaborator

@jasnell jasnell commented Jul 17, 2025

Per the spec, the currentTarget property of an Event should be null if the event is not being dispatched.

Fixes: #4558
Fixes: #4556

@danlapid @kentonv ... I'm hoping this can be something we don't need a compat flag for. Whatcha think?

Adds a new pedantic_wpt compat flag for these kinds of fixes. Additional changes will be made incrementally using implied_by compat flags so that'll bundle all these types of changes together.

/cc @npaun

Copy link
Member

@npaun npaun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implementation is very clear and simple.

Copy link

github-actions bot commented Jul 17, 2025

The generated output of @cloudflare/workers-types matches the snapshot in types/generated-snapshot 🎉

@jasnell
Copy link
Collaborator Author

jasnell commented Jul 17, 2025

Crap, I forgot that this would change the generated types. I think based on that alone we'll need a compat flag here... ugh.

@kentonv
Copy link
Member

kentonv commented Jul 17, 2025

I don't think changing the generated types in itself is a reason for a compat flag -- the types don't exist in production, after all, and compat flags are about protecting workers in production.

But whether the API change itself requires a compat flag, I don't know.

We could add logging to see if anyone actually calls this when !isBeingDispatched. If anyone does, then I think a compat flag is probably needed.

Though that doesn't really answer whether the undefined->null change in itself might require a compat flag, which I guess is harder to tell.

@kentonv
Copy link
Member

kentonv commented Jul 17, 2025

I wonder if we should create a new compat flag called wpt_pedantic or something, and accumulate all the little irrelevant changes needed to fix WPT tests into it. Once we have all the fixes done, only then do we set a default-on date.

That way we don't create a massive number of compat flags for little things nobody actually cares about...

cc @npaun

@jasnell
Copy link
Collaborator Author

jasnell commented Jul 17, 2025

That would make sense I think

@npaun
Copy link
Member

npaun commented Jul 17, 2025

@kentonv Yeah I've considered creating one a few times now

@jasnell
Copy link
Collaborator Author

jasnell commented Jul 17, 2025

I'll move this back to draft, add a compat flag, and will bundle multiple WPT fixes under this PR. We can likely do this in batches with several compat flags, one for each batch.

@jasnell jasnell marked this pull request as draft July 17, 2025 19:53
@jasnell jasnell force-pushed the jasnell/eventtarget-currenttarget-fix branch 2 times, most recently from 59d5a44 to e1256e0 Compare July 17, 2025 22:28
@jasnell
Copy link
Collaborator Author

jasnell commented Jul 17, 2025

PR updated to add the compat flag and also handle the isTrusted property pendantically. PTAL

@jasnell jasnell marked this pull request as ready for review July 17, 2025 22:30
@jasnell jasnell requested review from npaun, a team and kentonv July 17, 2025 22:30

pedanticWpt @101 :Bool
$compatEnableFlag("pedantic_wpt")
$compatDisableFlag("non_pedantic_wpt");
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review note: this intentionally has no disable enable date for now.

@@ -45,9 +45,7 @@ export default {
'EventTarget-addEventListener.any.js': {},
'EventTarget-constructible.any.js': {
comment: 'Should be null, not EventTarget',
expectedFailures: [
Copy link
Member

@npaun npaun Jul 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't there be a change relating to isTrusted here as well?

Copy link
Collaborator Author

@jasnell jasnell Jul 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought so too but it passed locally without it.. so... I was confused lol... wanted to see what the main CI did.

jasnell added 2 commits July 17, 2025 16:05
Per the spec, the currentTarget property of an Event
should be null if the event is not being dispatched.

Introduces a `pedantic_wpt` compat flag for correctly
handling these.
@jasnell jasnell force-pushed the jasnell/eventtarget-currenttarget-fix branch from 7285b2a to d61e1ed Compare July 17, 2025 23:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Event.currentTarget is set when it's expected to be null Event.isTrusted needs to be an own property not a prototype property
3 participants