-
Notifications
You must be signed in to change notification settings - Fork 679
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] Define before/after-change style in terms of base #6688
base: main
Are you sure you want to change the base?
Conversation
This needs a resolution, but proposing an edit ahead of time so we know exactly what to resolve on. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this looks good to me (although it has some compatibility risks... though perhaps low given that current implementations don't agree very much), but I think this either needs working group consensus or at least approval from the other implementors of transitions, in #6398.
It's possible the list could be further simplified at this point, but it will be easier to tell once this lands.
I think this represents a change to case 11 from https://bug1192592.bmoattachments.org/attachment.cgi?id=8843824. That is, I believe with this proposal it would be possible to trigger a transition while an animation is running. Maybe that's ok but it does seem a bit risky in terms of compatibility, since browsers appear to agree on that at the moment. Also, I'm really rusty on how all this fits together but I believe in Gecko at least SMIL animated styles are written to an override stylesheet separate to the animations level of the cascade whereas this PR seems to assume they are written to the animations level of the cascade. |
I think you're right. Although while the animation is running, the transition would add no effect value to the cascade. https://drafts.csswg.org/css-transitions-1/#application. But it would be observable via events, and when the animation ends sooner than the transition.
Oh, that's unfortunate. Thanks for pointing that out. I'll have to investigate more to know what makes sense there. |
Thanks. I'm not sure which is preferable. If there's time, adding the use counter would be safest. If we decide to change this behavior, I guess it would be little odd that transition events are fired even when there's no visual change. Maybe it's ok though. |
Thank you! |
@andruud any updates on this? |
Yes, but not the update I wanted. The use-counter is at almost 4%, which is way higher than expected. I've been waiting for sample pages to come in so I could check if there's any typical usage patterns we could use to argue that the change doesn't matter, but at 4% it might be futile to find the "typical" usage patterns anyway. So as it stands, the use-counter did not help in making a confident decision here, unfortunately. @birtles In light of this, do you think we should do the following?
|
I think so. Transition events are quite important to a lot of apps -- often various state changes are keyed off getting a (Anecdotally, many many years ago when working on Firefox OS, a recurring cause for apps breaking was that they didn't receive expected |
OK, thanks @birtles. I'll update this PR with new proposed text as soon as I can. |
Sounds good to me to make transitions not start if there is an animation on that property. I think you should look for animations in the after-change style so that we avoid starting a transition in the case in #8701. As an extreme use case, consider a page which makes use of both transitions and animations to move an element around, e.g. <style>
#target {
transition: transform 1s;
}
</style>
<script>
moveTo(transform) {
let animation = target.animate([{transform}], {duration: 1000, fill: 'forwards'});
animation.finished.then(() => {
// Changes the base style to match the animated position.
animation.commitStyles();
animation.cancel();
});
}
</script> The call to commitStyles should not start a transition (this would cause the element to move back to its old location and slide back to the target). I think this would be fine right now because the animation is still technically active, however we should also make sure that with #5394 you can omit the fill and have the animation technically not active in the final frame, i.e. bounceTo(transform) {
let animation = target.animate([{transform}], 1000);
animation.finished.then(() => {
// Changes the base style to match the animated position.
animation.commitStyles();
});
} In this case the animation is technically no longer active but was previously - so perhaps this is just justification to consider animations in the before or after change style? |
Trying to pick this back up (at the request of @dbaron), I have updated this PR:
Please review closely. |
- Introduce "base style", which is the computed style as it would be without animations/transitions. - Define before/after-change style in terms of that base style (at two different points in time). - There should be no need for the "completed transition" set anymore, since the before/after-change styles on a child are blind to any effects from transitions/animations happening on the parent. - Maintain the behavior that transitions can not start for properties affected by animations. Removing this behavior was considered, but was deemed impossible from use-counter data showing that ~5% of sites may rely on this behavior. This change stems from Container Queries, which blurred the line between the style and layout steps of the frame. The spec currently defines the before-change style as the style of the previous style change event, but with any animation effects updated to current time. This is difficult, because it persisting the before-change world in some form that is responsive to what the (newly updated) animations actually do. (For example, we'd need to re-resolve var(), font-relative units, be able to handle revert/revert-layer, etc.) With Container Queries, this problem becomes substantially worse, because now we'd also need to maintain the "before-change layout tree", which in practice is gone at the time we need it. w3c#6398
So to capture my working, in #5394 we're proposing that calling Suppose we have an animation from width 100px to 200px, no fill mode, and we call Let's assume the unanimated width (i.e. base style width) is 50px (just to make it easier to distinguish the animation style from the base style).
Does that seem right? |
The call to <code>commitStyles()</code> | ||
will trigger a <a>style change event</a>, | ||
with the <a href="#before-change-style">before-change</a> | ||
<code>width</code> being <code>100px</code>, | ||
and the <a href="#after-change-style">after-change</a> | ||
<code>width</code> being <code>200px</code>. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is right? The style change event occurs before the inline style is updated so the before-change
and after-change
width at this point should both be 100px?
@birtles Ah, I was not aware that |
[css-transitions-1] Define before/after-change style in terms of base
without animations/transitions.
(at two different points in time).
since the before/after-change styles on a child are blind to any
effects from transitions/animations happening on the parent.
affected by animations. Removing this behavior was considered,
but was deemed impossible from use-counter data showing that ~5%
of sites may rely on this behavior.
This change stems from Container Queries, which blurred the line
between the style and layout steps of the frame. The spec currently
defines the before-change style as the style of the previous
style change event, but with any animation effects updated to
current time. This is difficult, because it persisting the before-change
world in some form that is responsive to what the (newly updated)
animations actually do. (For example, we'd need to re-resolve var(),
font-relative units, be able to handle revert/revert-layer, etc.)
With Container Queries, this problem becomes substantially worse,
because now we'd also need to maintain the "before-change layout tree",
which in practice is gone at the time we need it.
#6398