Skip to content

Angular 14 unnecessarily warning about not animatable properties? #46602

Closed as not planned

Description

@diegovilar

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

  1. added
    area: animations
    on Jun 29, 2022
  2. added this to the needsTriage milestone on Jun 29, 2022
  3. AndrewKushnir commented on Jun 29, 2022

    @AndrewKushnir
    Contributor
  4. dario-piotrowicz commented on Jun 29, 2022

    @dario-piotrowicz
    Contributor

    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 style function is evaluated it is in the context of animations, there is no distinction between style being 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 style function, something like ignoreNonAnimatableProps to suppress the warning, or something similar 🤔

    Anyways personally I think that style should 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 😓), using style inside animations to set some non animatable props feels a bit like a misuse of the function to me.

  5. jessicajaniuk commented on Jun 29, 2022

    @jessicajaniuk
    Contributor

    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.

  6. diegovilar commented on Jun 29, 2022

    @diegovilar
    Author

    @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 style function is evaluated it is in the context of animations, there is no distinction between style being 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 style function, something like ignoreNonAnimatableProps to suppress the warning, or something similar 🤔

    @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.

  7. dario-piotrowicz commented on Jun 29, 2022

    @dario-piotrowicz
    Contributor

    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 style being 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? 🙂

  8. diegovilar commented on Jun 29, 2022

    @diegovilar
    Author

    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 style being 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

    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 🤗

  9. dario-piotrowicz commented on Jul 1, 2022

    @dario-piotrowicz
    Contributor

    @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):
    before
    after

    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)

  10. diegovilar commented on Jul 5, 2022

    @diegovilar
    Author

    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 🤗

  11. dario-piotrowicz commented on Jul 5, 2022

    @dario-piotrowicz
    Contributor

    Fantastic, @dario-piotrowicz! Sorry for the delay, was on the road slightly_smiling_face

    Just read the discussion on your PR and I hope it gets merged soon. Thanks again for the great work hugs

    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)

  12. added a commit that references this issue on Jul 12, 2022
    c603969
  13. added 2 commits that reference this issue on Jul 12, 2022
    a4ec109
    862dd03
  14. dario-piotrowicz commented on Jul 15, 2022

    @dario-piotrowicz
    Contributor

    @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 😊

  15. dionatan-g commented on Jul 21, 2022

    @dionatan-g

    This PR didnt fix all the false positive warnings.

    For example here, I have warnings:

    export const collapse: AnimationTriggerMetadata = trigger('collapseAnimation', [
      state('expanded', style({ height: '*', visibility: 'visible' })),
      state('hidden', style({ height: 0, overflow: 'hidden', borderTopWidth: '0', visibility: 'hidden' })),
      transition('expanded => hidden', animate(`150ms ${AnimationCurves.EASE_IN_OUT}`)),
      transition('hidden => expanded', animate(`150ms ${AnimationCurves.EASE_IN_OUT}`)),
    ]);
    

    For me to remove the overflow hidden, I would have to set the style manually with the same delay as the animation.

  16. dario-piotrowicz commented on Jul 22, 2022

    @dario-piotrowicz
    Contributor

    @dionatan-g, I'm going to reply in the issue you've created 👍

    (adding it here if anyone is following this thread: #46928)

  17. angular-automatic-lock-bot commented on Aug 22, 2022

    @angular-automatic-lock-bot

    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.

  18. locked and limited conversation to collaborators on Aug 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: animations

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions