question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Safari: keyframes not working as expected

See original GitHub issue

Which @angular/* package(s) are the source of the bug?

core

Is this a regression?

No

Description

When using the API to define elements inline, keyframes animation seems to require the ‘from’ property to be explicitly set in Safari/iOS Safari only. According to the W3C spec, this property is supposed to be optional.

Please provide a link to a minimal reproduction of the bug

https://stackblitz.com/edit/angular-ivy-9nih37?file=src%2Fstyles.css

Please provide the exception or error you saw

Not applicable

Please provide the environment you discovered this bug in

Angular CLI: 12.1.0
Node: 14.17.3
Package Manager: npm 7.20.0
OS: Mac OS, iOS

Anything else?

  1. Open the Stackblitz example in Chrome. Notice that a small green line is animated.
  2. Open the Stackblitz example in Safari. Notice that the small green line is not animated.
  3. Go to styles.css in the example and try uncommenting the ‘from’ property. Notice that the line animates as expected.

When using vanilla HTML/Javascript/CSS, this issue is not reproducible. See this Stackblitz.

In the Angular example, the length of the line affects the correct setup for the animation. That will sometimes only be known at runtime, which is why omitting the ‘from’ property is handy.

WORKAROUND: Using the Web Animations API seems to work in all browsers. The Angular example includes an example of this workaround. The intended code:

const length = line.getTotalLength();
line.style.strokeDasharray = `${length} ${length}`;
const lineAnimationTiming: EffectTiming = {
      duration: 1000,
      easing: 'ease-in-out'
};
line.animate(
    [
    { strokeDashoffset: length },
    { strokeDashoffset: 0 }
    ],
    lineAnimationTiming);

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
petebacondarwincommented, Oct 26, 2021

Thanks to both @dario-piotrowicz and @jzabinski-dolios for your excellent analyses. I will close this as it appears the problem is with the browser and not Angular.

1reaction
jzabinski-dolioscommented, Oct 26, 2021

Thank you @dario-piotrowicz! That makes a lot of sense; I agree that this is likely a timing issue. I don’t know very much about the inner workings of Webkit browsers, but based on some experiments yesterday, the Javascript framework seems to run in a separate process. (Following these instructions, I tried to install the latest Webkit build to test that. MacOS security protocols pretty much destroyed the installation process, but whenever the security protocols disrupted something, they would inform me as to which process was disallowed. These processes always seemed to launch in no particular order.)

That being said, I confirmed that your workaround of installing the animation CSS after those elements are initialized works well in both Safari and Safari Tech Preview.

It sounds like, for Safari, if we want to dynamically load animated elements, the animation CSS needs to always load after the element is initialized. To ensure that, we have two options:

  1. Dynamically load the CSS after loading the element, via setTimeout and .innerText
  2. Use the Element.animate method

Thanks so much for working through this with me. I’m fine with closing this bug, and letting Webkit handle it (if they so choose).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Safari Keyframes not working - Stack Overflow
Safari requires the prefixed -webkit-animation property. #slider figure { position: relative; width: 500%; margin: 0; left: 0; text-align: ...
Read more >
Keyframe animation not working in Safari? - HTML & CSS
I have a keyframe animation that works just fine in firefox and chrome, but wont start in Safari for some reason. Here is...
Read more >
CSS Animations Not Working? Try These Fixes - HubSpot Blog
Whether your animation isn't working as intended, or just isn't working at all, here are some reasons why and how you can resolve...
Read more >
iOS 15.1 not displaying some @keyframe tr…
I've spoken with users of at least 5 different iOS 15.1 devices, using both Chrome and Safari. The animation in this codepen link...
Read more >
Keyframes not working on safari : r/webdev - Reddit
Hello, So I have a few keyframe animations in my site and they dont seem to be working on Safari. What could be...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found