-
Notifications
You must be signed in to change notification settings - Fork 689
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-variables] When does substitution occur, before or after animation interopolation? #411
Comments
I've looked at the Houdini minutes and there was a breakout session regarding this but I can't seem to find minutes. At any rate, basically I'm trying to understand what the preferred expectation is regarding the following code:
Should the div be:
|
Hi @gregwhitworth, I agree the first & third divs should flip at 50% between red and blue, from With the patches to implement Properties & Values on Firefox, we do get the 50% flipping behavior, as required by the Properties & Values spec. Firefox's behavior looks correct for the second div. The |
@gregwhitworth My expectation is that the div's background flips from blue to yellow. (If that didn't work, the whole "animation-tainted" concept wouldn't be worth much.) The spec does need a little bit more detail there, but the general principle is supposed to be that animations run before we do variable substitution. |
I agree with Tab - the animation's variable should be used in computation of the style of the div. The fact that --foo is animation-tainted doesn't matter (I think Tab's pointing out we wouldn't need to bother with animation tainting if animation variables couldn't leak into the environment). I guess what's important is that the animation's variable "wins out" over the one defined in the div rule, but this is just normal - e.g. imagine if you set background directly in the animation instead. |
@shans @tabatkins Thanks, this is what we were expecting and kind of shocked that currently no one implements it this way. Does Chrome plan to address this, I would assume so since you're working on the Houdini Custom Props which was primarily created for extending the animation capabilities that are somewhat limited due to needing to substitute post animation. |
One last comment, I highly recommend adding it the example I provided with the expected outcome and why. While animation may be considered part of the "cascade" in the Cascade spec it is actually done on the computed results of the cascade. I think this example shows implementers what the expected behavior is, and also informs them that substitution should occur after animation which is currently not stated anywhere, at least not in plain language (it may be implied). |
Going to reopen until the spec update is done, assigning to @tabatkins since he's the editor. |
@tabatkins @shans and myself spoke about animating custom properties and how many substitutions you need in order to support use cases the authors would expect to work. I recommend adding the following copy as a note for an example implementation to ensure the spirit of the specification is followed by all implementations (which when we began this implementation no UA supports this, so it would be good to ensure it's in there). In order to be able to make the use cases work, here is what an example implementation would look like:
While this will help solve some of the gaps and interop issues we found while implementing custom properties, I think we should specify these steps normatively in somewhere (possibly the cascading specification) so that we can reference them and better understand the potential use case and perf impacts with future feature discussions (eg: @apply). |
@tabatkins any thoughts on this? And @fantasai any thoughts on normalizing these steps in the cascade spec so in the future when discussing these types of features and people use the terms such as "an at-apply" point or a "substitution" point; we can better reason about them? |
Hey @tabatkins do you want me to do a PR on this? |
Going to reopen until the spec update is done, assigning to @tabatkins since he's the editor.
@gregwhitworth a PR would be great. Also, a test case on WPT that tests the change (or a link to a test that already tests this). |
Okay so I've been researching this to finally get a proper answer down in the spec, and the answer seems, uh, complicated. Firefox, as far as I can tell, takes an easy route: custom properties defined directly on the element are visible to animations (can be used as var() inside of @Keyframes), but custom properties defined in @Keyframes aren't visible to properties directly on the element. (They are visible to other rules in the same keyframe, but not cross-keyframe.) Chrome does something more complicated that I'm still puzzling out. It has all of Firefox's cross-context behavior, plus custom properties defined in @Keyframes are visible to the element itself. They appear to be visible cross-animations, too; that is, a custom property animated by one @Keyframes can be used by a different @Keyframes. Exactly how it determines which properties are visible to what, when, looks complex; I think animation order matters; keyframe temporal ordering might matter, but I haven't gotten a testcase together to demonstrate it for sure yet. So I'm gonna do some more exploratory work on this and possibly bug Chrome/WK implementors about details before I commit to something to bring to the group. |
tldr: As far as I can tell, browsers are currently treated variables in animations differently than other computed-value dependencies, and they should stop. The correct behavior was resolved back in 2014, but hasn't been put into the Animations spec. Once it is editted in, variables behavior should naturally fall out, and we don't need any special text for this spec. When figuring out how custom properties work with animations,
That is:
So there's a 4x4 matrix (with many cells being dupes) Tests for each situation (named for custom prop location and var() location, like Chrome ✔✘, Firefox ✔✘
Firefox's overall rule seems to be that custom props defined on the element are visible to animations, I think both can be explained in the same way, with a single change in var() substitution timing: Reviewing some old animation issues In particular:
So I think the behavior is actually just something that should fall out of the Animations spec I initially thought it might still require some special text, The general behavior will likely be, then, |
I think the spec could be a little bit more clear on when substitution actually occurs for custom properties. We know that they happen during computed value time, but this doesn't get into the minutia of whether or not this occurs before the animation interpolation or after.
If you take the following example, what should happen:
http://jsbin.com/busapezohu/1/edit?html,css,output
Chrome: No background is painted for either div
FF: Second div background is transitioned
Currently the spec states the following:
This seems to state that they should work, but that it may not be possible to correctly interpolate a custom property (as seen in the
test
animation since it's merely an ident at that point). So I would suggest that what Firefox is doing is the correct outcome, that you do substitution first and then any animation interpolation once we know the value and the property it is applied to is blue we can correctly interpolate to that of blue (as seen in the regular testcase).This may even want to be taken over to the cascade specification where we get more specific about when certain things happen during various stages, in this case Computed Value time.
cc: @shans as this is what I was pinging you about :)
The text was updated successfully, but these errors were encountered: