Skip to content

"first-input" dispatch logic in the spec doesn't match the tests and the Chromium implementation #142

Closed

Description

@canova

Hi! I was looking at the failing tests that we have in Firefox and noticed an inconsistency between the spec and web platform tests + chromium implementation.

I was looking at this test which was returning mousedown instead of pointerdown for the first-input (that assertion happens here).

The calculation for the first-input happens inside "3.9. Dispatch pending Event Timing entries" and step 6. But specifically look at 6.2.2:

Otherwise, if name is one of "click", "keydown" or "mousedown", then:
(dispatch first-input)

But looking at the chromium implementation, it shows another condition: !first_pointer_down_event_timing_

In Firefox, our implementation doesn't have this check as we follow the spec, and the tests are failing because of it. Either we need to update the spec and Firefox. Or we need to update the tests and Chromium (which sounds more unlikely).

If the spec needs an update, my wording recommendation would be:

Otherwise, if name is one of "click", "keydown" or "mousedown", AND if window’s pending first pointer down is null, then:

Please let me know what you think! I field this bug in Firefox in the meantime.

Activity

  1. mmocny commented on Feb 19, 2025

    @mmocny
    Collaborator

    I think the best solution is for the first-input entry to be the first event which fires (according to UI Event spec).

    In chromium, that is pointerdown. Is pointerdown also the first event in FF?

    If so, I suggest we update the spec to remove the special language for the ordering of event types and instead to define first-input in terms of the first event which is an interaction. (I think we have an open issue to do this).

  2. mmocny commented on Feb 19, 2025

    @mmocny
    Collaborator

    I think this is the relevant issue: #139

    I was supposed to make changes to this text already, based on past discussions in the WG, but I had not done so yet.

    If you could check, and if you agree, that the changes would better match actual web platform event dispatch behaviour also in FF, that would be ideal!

  3. canova commented on Feb 19, 2025

    @canova
    MemberAuthor

    Thanks for the quick response! Looping @sefeng211 in here as well.

    In chromium, that is pointerdown. Is pointerdown also the first event in FF?

    Yes, that's also the case in Firefox.

    I think marking the first input as first event that fires could make sense. But I was talking with @sefeng211 yesterday and he pointed out that the spec mentions that we expose the pointerdown event only if it's followed by a pointerup. (in the spec link, see below the list wording that says "pointerdown which is followed by pointerup"). I think this distinction comes from the fact that if pointerdown is followed by a pointerup it means it's a touch event and otherwise it's a mouse event.

    Note that these are the order of events that are fired for a touch and for a click in Firefox (assuming it's the same in Chrome):

    touch: pointerdown -> pointerup -> mousedown -> mouseup -> click
    mouse: pointerdown -> mousedown -> pointerup -> mouseup -> click
    

    But I also agree with your idea of evolving this into "first interaction". I think it's more correct if we show whichever interaction event is being fired first as a first input. But would love to hear from @sefeng211 too.

  4. mmocny commented on Feb 19, 2025

    @mmocny
    Collaborator

    The distinction is meant to ignore touch based scrolling (well, certain other flows as well, see note below).

    If there is a pointerdown without a pointerup, it means there was a pointercancel instead. Although we did dispatch a pointerdown event, we do not want to consider it a first-input candidate (nor an interactionId candidate).

    This could only happen on a touch device (or stylus?). And, when this happens, there should also not be a mousedown event dispatched at all (that is because mousedown is simulated on pointerup, I think).

    So, I think there is no legitimate case where you could have a mousedown, but not a pointerdown+pointerup pair, and so pointerdown should always come before mousedown.

    (Historically in Chromium, I think there were certain flows where this special case did cause us to accidentally report mousedown event out of order-- but in hindsight it was a mistake-- since in those cases we were accidentally reporting what was not the first input event. I think we should never hit these cases in Chromium (soon), and after settling this here and in spec, I intend to remove these special cases from Chromium entirely.)


    In terms of pointerdown without pointerup --- another case we found in Chromium was that on some platforms when you hit contextmenu event this is equivalent to a pointercancel. I think on some platforms or in some cases you still also get the pointercancel event but not always-- so we treat both as a cancel signal.

    I think that last time I looked, the UI Events spec was not super clear about this, and I'm not actually sure if Chromium should be fixed to fire pointercancel consistently. Depending on the answer, Event Timing may or may not want to add to the spec language the contextmenu event (I.e. I'm not sure if its just a chrome workaround...)

  5. canova commented on Feb 19, 2025

    @canova
    MemberAuthor

    Thanks for the detailed answer again! I see, then considering all of these, it might be best to update the spec, and update Firefox to match this behavior. I'll be updating my patch in bugzilla to match this it. Note that we still don't have interactionId, but hopefully soon :)

  6. canova commented on Feb 20, 2025

    @canova
    MemberAuthor

    I changed my patch to reflect this behavior in Firefox, but I would like to wait until either we have this in the spec, or we have a confirmation from all vendors of interop 2025 before landing it.

    @annevk
    Hi, Would you be okay with the spec change mentioned in #142 (comment)?

  7. self-assigned this
    on Feb 25, 2025
  8. added a commit that references this issue on Mar 7, 2025
  9. mmocny commented on Feb 26, 2026

    @mmocny
    Collaborator

    @canova I think we updated the spec, and you updated the FF implementation, and I'm currently working on changing the Chrome implementation, to make it so e.g. mousedown can never be FID since pointerdown will always be first (thats just one symptom from earlier in this thread-- the main solution is to always match first event-timing with non-0 interactionId)

    I was wondering if you already audited or updated all the FID WPT? I can take a look if you havent, I just dont recall if this was already resolved last year...

  10. canova commented on Apr 14, 2026

    @canova
    MemberAuthor

    Hey @mmocny, sorry for missing this ping!

    Yes, I just checked again and I can see that both Firefox and the wpt side matches this updated behavior now. I think I did these as a part of Bug 1934683 and Bug 1948647.

  11. mmocny commented on Apr 14, 2026

    @mmocny
    Collaborator

    Fantastic. Marking as closed, cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions