Skip to content

[css-transitions-2][css-animations-2] The event order of the cancelled transitions/animations #11064

Closed

Description

@BorisChiou

Recently, we noticed a Gecko bug about the event order of transitioncancel in Bug 1923208. Per the example this bug, we may have a case when transitioncancel and transitionrun have the same scheduled time.

The example is something like this, when we are replacing a running transition:

<script>
function run() {
  target.style.marginLeft = "100px; // We start to run a transition.
  setTimeout(() => {
    target.style.marginLeft = "200px"; // We replace the running transition
  }, 500);
}
</script>
<body onload="run()">
  <div id="target" style="transition: margin-left 100s;"></div>
<body>

So basically, in Blink and Webkit, the event order when replacing the transition is:

transitioncancel, transitionrun, .transitionstart

However, in Gecko, the order is:

transitionrun, transitionstart, transitioncancel

These events have the same schedule time, and Gecko puts transitioncancel last.

Per spec, we use the following way to decide the order of them (copied from the comments in the bug):

  • If the scheduled event times are the same then the algorithm is to sort by composite order. That's going to mean we sort as follows:

      If A and B’s associated animations differ by class, sort by any inter-class composite order as defined for the corresponding classes.
      If A and B are still not sorted, sort by any class-specific composite order defined by the common class of A and B’s associated animations.
      If A and B are still not sorted, sort by the position of their associated animations in the global animation list.
    
  • Since the classes are the same ("transition"), we'll sort by the transition-specific composite order, and then we'll hit step 2 there because the cancelled transitions don't have the owning element:

      Otherwise, if only one of A or B has an owning element, let the animation with an owning element sort first.
    

So it seems we should put the event of the cancelled transition first because it doesn't have the owning element. However, this is not what we expected because we cancel the transition first, and then create the new transition to replace the old one.

We may need to update the spec words to address the case for cancelled transition, e.g. per Brian's suggestion in this Gecko bug:

When sorting cancel events, use the owning element and transition generation from when the transition was cancelled

Also, we have the similar issue for animationcanel (in css-animations-2), and we probably need to figure out how to use animation-name for a cancelled animation.

cc @birtles

Activity

  1. birtles commented on Oct 30, 2024

    @birtles
    Contributor

    Also, we have the similar issue for animationcancel (in css-animations-2), and we probably need to figure out how to use animation-name for a cancelled animation.

    I had a bit of a think about this. For CSS animations we sort by:

    1. Tree order
    2. Position in the animation-name list

    So how do we handle cancel events from animations that have been cancelled? Consider a few examples of changes to animation-name list with regards to cancel event ordering:

    Case A: If we change animation-name from a, b to c, b we want to ensure the cancel event for a sorts before the start event for c since that's consistent with transitions and conceptually it makes sense to cancel old animations before adding new ones.

    Case B: If we change animation-name from a, b, c to c we would probably prefer that the cancel event for a sorts before the cancel event for b. It's not very important but we need to define some order and a, b seems the most obvious one here.

    Case C: What if the animation-name is originally a, b, c, then, in a separate style change updated to b, a, c and then later updated again to c? It would probably be most consistent for the cancel event for b to the dispatched before the cancel event to a since b appeared before a in the animation-name at the point when they were cancelled.

    Given that, I think we could sort as:

    1. Sort by owning element
    2. Sort by position in the animation list. If either animation has been cancelled, use the position they were in the list when they were cancelled but treat such positions as sorting before all positions in the current list.

    So, for example, if both A and B have been cancelled, we just sort by the old positions in the list.

    If only A or B has been cancelled, the cancelled animation sorts first.

    If neither A nor B have been cancelled, we sort by the positions in the current list.

  2. birtles commented on Oct 30, 2024

    @birtles
    Contributor

    Proposed spec edits:

    1. In CSS Transitions level 2, Animation composite order add some introductory text:

      When determining the composite order to sort transition events where either or both of the events is a transitioncancel event, use the owning element and transition generation that were set immediately prior to cancelling the transition.

    2. In CSS Animations level 2, Animation composite order add:

      When determining the composite order in order to for sort animation events where either or both of the events is an animationcancel event, treat the CSS Animation(s) for which the event was generated as having an owning element corresponding to the owning element in use at the point where the CSS Animation was cancelled. Furthermore, use the position of the animation in the 'animation-name' property in effect at the time when the CSS Animation was cancelled sorting such that positions of cancelled animations sort before positions of animations that have not been cancelled.

    That last sentence in particular probably needs work but that's the gist anyway.

  3. added a commit that references this issue on Nov 29, 2024
  4. dbaron commented on Jan 14, 2026

    @dbaron
    Member

    I'd like to propose an async resolution to accept the edits for this issue, at least assuming my reasoning that follows is correct. This is the one normative change in css-transitions-2 since the last publication, so the WG accepting these edits would mean, I think, that the editors are free to republish as a new WD.

  5. astearns commented on Jan 26, 2026

    @astearns
    Member

    The CSSWG will automatically accept this resolution one week from now if no objections are raised here. Anyone can add an emoji to this comment to express support. If you do not support this resolution, please add a new comment.

    Proposed Resolution: Accept the edits for the event order of cancelled transitions/animations

  6. astearns commented on Feb 2, 2026

    @astearns
    Member

    RESOLVED: Accept the edits for the event order of cancelled transitions/animations

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions