Repository navigation
Description
Which @angular/* package(s) are the source of the bug?
animations
Is this a regression?
No
Description
It seems Angular 14 is warning about the presence of not animatable style attributes in a transition() call whether or not the implementation sets them as part of an animate() call.
In the following implementation, styles set in query(":enter, :leave") are preparation styles to be applied for the duration of the transition but are not set up to be animated. Still I get a warning about position and overflown not being animatable.
transition("* => fade", [
style({ position: "relative" }),
query(":enter, :leave", [style({
position: "absolute",
inset: "0 0 0 0",
overflow: "hidden",
})]),
query(":enter", [style({ opacity: 0 })]),
query(":leave", [animateChild()]),
group([
query(":enter", [animate("150ms ease-out", style({ opacity: 1 }))]),
query(":leave", [animate("50ms", style({ opacity: 0 }))]),
query("@*", [animateChild()]),
]),
]);The animate() calls above are specific about which attributes are to be animated, so they are not trying to animate towards all the attributes of the destination state.
Am I wrong in my understanding of how transitions in Angular work or is the compiler being unnecessarily critic in the new version?
Please provide a link to a minimal reproduction of the bug
No response
Please provide the exception or error you saw
The animation trigger "ngxRouterAnimation" has built with the following warnings:
- The following provided properties are not animatable: position, overflow
(see: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_animated_properties)
Please provide the environment you discovered this bug in (run ng version)
Angular CLI: 14.0.2
Node: 16.15.1
Package Manager: pnpm 7.3.0
OS: linux x64
Angular: 14.0.3
... animations, cdk, common, compiler, compiler-cli, core, forms
... language-service, material, platform-browser
... platform-browser-dynamic, router
Package Version
---------------------------------------------------------
@angular-devkit/architect 0.1400.2
@angular-devkit/build-angular 14.0.2
@angular-devkit/core 14.0.2
@angular-devkit/schematics 14.0.2
@angular/cli 14.0.2
@schematics/angular 14.0.2
ng-packagr 14.0.2
rxjs 7.5.5
typescript 4.7.4
webpack 5.73.0
Anything else?
No response
Activity
AndrewKushnir commentedon Jun 29, 2022
// cc @dario-piotrowicz
dario-piotrowicz commentedon Jun 29, 2022
Thanks for tagging me @AndrewKushnir 🙂
Yeah I indeed added the check in PR #45212
@diegovilar it is not that the code is being more critic, I added that functionality to provide a better experience for developers so that if they see that something is not being animated then they can easily identify what is going wrong.
So regardless on the warnings, if your code worked fine prior to Angular 14, it will work exactly the same in 14, as the only difference is the warning being shown (note that it is also a dev only warning, there is no effect in production at all).
Anyways the thing is that in when the
stylefunction is evaluated it is in the context of animations, there is no distinction betweenstylebeing called on it's own or being part of an animation (and personally I am not sure there should be such distinction), it could be tricky to implement but I could give it a shot if needed 🙂One very simple alternative would be to add an optional options parameter to the
stylefunction, something likeignoreNonAnimatablePropsto suppress the warning, or something similar 🤔Anyways personally I think that
styleshould only be used as part of an animation implementation, and not in order to set non-animation related styles to elements, for that trigger callbacks could be used instead (it would be more verbose I know 😓), usingstyleinside animations to set some non animatable props feels a bit like a misuse of the function to me.jessicajaniuk commentedon Jun 29, 2022
Thanks for the detailed response, @dario-piotrowicz. @diegovilar I'm going to close this as working as intended, but if you have suggestions, feel free to continue to comment here. We welcome the improvement ideas. Thanks for reporting this.
diegovilar commentedon Jun 29, 2022
@dario-piotrowicz I see how tricky it could be to improve the code to detect if the developer is really trying to animate not animatable properties. Probably unnecessary too.
The new warnings do provide a better experience for the developers, as was your intention, but when warnings keep being issued even when a developer analyzed them and decided that they are not applicable, they end up obfuscating newer warnings and those might slip by, thus worsening the experience. Your idea of allowing the developer to explicitly disable the warnings for a
style()call sounds great. They would be warned, would analyze the code and either fix it or disable the warnings if there is nothing to fix, kinda like locally disabling an eslint rule for a line.dario-piotrowicz commentedon Jun 29, 2022
Thanks @diegovilar! 🙂
Yeah I understand your point of view and it'd be my pleasure to add an option like that, again I am not a big fan of
stylebeing used like that but it is not like completely wrong, and providing the possibility for devs to make their own decision does sound better instead of trying to force things@jessicajaniuk, would you be ok with me looking into adding such an option? 🙂
diegovilar commentedon Jun 29, 2022
There is a legion of developers out there using
style()to set up temporary properties for the duration of the transition, probably because the Route transition animations guide on Angular.io itself teaches it that way 😅. Personally, I do think there are cases where that is a valid use, specially in route transitions that you end up having to "detach" the components temporally.Anyways, thanks for the quick response, folks 🤗
dario-piotrowicz commentedon Jul 1, 2022
@diegovilar I implemented the check for actually providing the warning only if the animation is trying to animate them
As you can see here, it does the trick (I copied your animations code but I applied a random html to it since you didn't provide one):


It has the drawback to be run when you play the animation instead of at build time, so you get the warning each time the animation runs instead of just when the component gets generated. This makes sense from the implementation point of view because it makes it easy to check if for an animation a non-animatable property is going to be animated.
Hopefully it's not too bad? I guess we shall see what reviewers say on the PR :)
Maybe this could be somehow also done on the animation build time but that I think would introduce a lot of complexity (and thus would be much more prone to bugs I'd imagine)
diegovilar commentedon Jul 5, 2022
Fantastic, @dario-piotrowicz! Sorry for the delay, was on the road 🙂
Just read the discussion on your PR and I hope it gets merged soon. Thanks again for the great work 🤗
dario-piotrowicz commentedon Jul 5, 2022
My pleasure! 😃
Yeah fingers crossed that it'll get merged soon 🙂
(by the way you can also notice that it wasn't as a difficult of a change as I imagined it could be, it was little more than just changing where/when the check is performed)
refactor(animations): refactor non-animatable check to be timeline based
refactor(animations): refactor non-animatable check to be timeline ba…
refactor(animations): refactor non-animatable check to be timeline ba…
dario-piotrowicz commentedon Jul 15, 2022
@diegovilar the PR got merged and I just checked, version 14.0.6 includes the fix, please try to see if you can update to that and see if it's all good now 😊
dionatan-g commentedon Jul 21, 2022
This PR didnt fix all the false positive warnings.
For example here, I have warnings:
For me to remove the overflow hidden, I would have to set the style manually with the same delay as the animation.
dario-piotrowicz commentedon Jul 22, 2022
@dionatan-g, I'm going to reply in the issue you've created 👍
(adding it here if anyone is following this thread: #46928)
angular-automatic-lock-bot commentedon Aug 22, 2022
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.