Skip to content
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

[css-transitions-1] Clarify timing of transitionrun and transitionstart #11665

Open
flackr opened this issue Feb 6, 2025 · 2 comments
Open
Labels
css-transitions-1 Current Work

Comments

@flackr
Copy link
Contributor

flackr commented Feb 6, 2025

If you load https://flackr.github.io/web-demos/css-transitions/event-timing.html and click the test button you can see the precise ordering of events when a transition is triggered.

Interop difference, Safari notably fires transitionrun, transitionstart before the next requestAnimationFrame, where Chrome and Firefox don't fire these events until the following frame.

Even more surprisingly though, this occurs even if you access the animation immediately calling target.getAnimations() (check the flush style checkbox). I think as a developer I would expect that if the animation is returned by getAnimations that it should fire transitionrun as part of dispatching animation events before the next raf

transitionrun says:

The transitionrun event occurs when a transition is created (i.e., when it is added to the set of running transitions).

Notably, the definition of running transitions says:

Each of these transitions also has a start time, end time, start value, end value, reversing-adjusted start value, and reversing shortening factor.

The transition may not yet have a start time if it is composited, which may be a good reason to defer transitionstart, however I think as a developer I would expect transitionrun to fire right away.

Related chromium issue: https://issues.chromium.org/394767658

@flackr flackr added the css-transitions-1 Current Work label Feb 6, 2025
@bramus
Copy link
Contributor

bramus commented Feb 6, 2025

The transition may not yet have a start time if it is composited, which may be a good reason to defer transitionstart, however I think as a developer I would expect transitionrun to fire right away.

+1 to this suggestion. transitionrun not firing immediately (in Chrome and Firefox at least) is currently an issue when building a custom style observer to respond to style changes: it fires a frame too late, potentially causing glitches as explained here.

@birtles
Copy link
Contributor

birtles commented Feb 8, 2025

If you load https://flackr.github.io/web-demos/css-transitions/event-timing.html and click the test button you can see the precise ordering of events when a transition is triggered.

Interop difference, Safari notably fires transitionrun, transitionstart before the next requestAnimationFrame, where Chrome and Firefox don't fire these events until the following frame.

I might be misunderstanding the test, but if you force a style flush, Firefox also dispatches transitionrun before the next animation frame:

Image

I think the more precise definition of transition events is in level 2 but it could probably be clarified that that if the transition did not exist in the previous frame it should be treated as "idle" for the previous frame (or simply update the chart to say "idle or non-existent").

+1 to this suggestion. transitionrun not firing immediately (in Chrome and Firefox at least) is currently an issue when building a custom style observer to respond to style changes: it fires a frame too late, potentially causing glitches as explained here.

I think transition events are a bit of a blunt instrument for observing animation state. For example, there's no event when the user updates an animation's duration. Internally Firefox has an animation observer interface which is used by DevTools. I wonder if it might be useful to standardise something like that in future as I've wanted it a few times and it's come up in a number of other issues too, from memory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
css-transitions-1 Current Work
Projects
None yet
Development

No branches or pull requests

3 participants