dom icon indicating copy to clipboard operation
dom copied to clipboard

Event.composedPath() inconsistency between implementors.

Open Jack-Works opened this issue 2 years ago • 5 comments
trafficstars

For code

const target = new EventTarget()
target.addEventListener('change', (event) => {
    console.log(event.composedPath())
}, { once: true })
const event = new Event('change')
target.dispatchEvent(event)

Chrome and Safari prints [], Firefox prints [target]

https://dom.spec.whatwg.org/#dom-event-composedpath

Per spec, it looks like Firefox is correct.

Jack-Works avatar May 22 '23 12:05 Jack-Works

I think that's right. Would you be willing to add web-platform-tests coverage? Edit: there are some tests for composedPath() in the /shadow-dom/ directory, not nothing covering this. Perhaps even better to add to /dom/events/ given that shadow trees are not involved in your scenario.

cc @rniwa @mfreed7

annevk avatar May 22 '23 12:05 annevk

I wonder which behavior is expected? Since the name composedPath indicates it is for DOM Node, the list missing pure EventTarget might be intended.

Jack-Works avatar May 22 '23 12:05 Jack-Works

Fair, might be good to wait a bit for others to chime in. In my mind this was always the event's path, but we didn't call it that because it had to be partially obscured in the presence of shadow trees. So I would expect Firefox's behavior and if we ever added the ability for userland EventTarget to hook into "get the parent" that would be reflected here as well.

(These days we would probably not add an API that so casually reveals open shadow trees however.)

cc @smaug----

annevk avatar May 22 '23 12:05 annevk

the name composedPath indicates it is for DOM Node

I’m unsure what about the name suggests that. While EventTargets constructed directly from user code never have a non-default “get the parent” algorithm presently, IndexedDB interfaces extending EventTarget do — an IDBRequest’s parent is an IDBTransaction and an IDBTransaction’s parent is an IDBDatabase. The usual bubbling behavior applies.

As far as I can tell, composedPath() for e.g. an IDBRequest success event should reflect this, and in Firefox, it does:

image

In Chromium presently, I get an empty array.

bathos avatar May 26 '23 11:05 bathos

So should I open the issue in Chrome and Safari?

Jack-Works avatar May 27 '23 06:05 Jack-Works