amp-img doesn't load when initial size is zero (animations)
What's the issue?
amp-img does not load image when its initial size is zero, even if the size becomes greater than zero later.
How do we reproduce the issue?
The demo shows a rotating card animation. At the first frame the image is rotated 90deg around the Y-axis so it's rendering width is zero. Its transform matrix is animated to rotate the image: https://jsbin.com/zoxafihuco/edit?html,output
The same animation can be achieved by setting opacity to 0 to hide the image at first frame, and reset it to 1 in later frames to show the transform animation. In this case, the image is loaded correctly. https://jsbin.com/belaxurapi/edit?html,output
What browsers are affected?
Chrome 70
Which AMP version is affected?
1811091510240
One solutions is having amp-animation force layout on all targets when it initializes. We wouldn't want runtime to try to schedule as animations run. @jridgewell What do you think? (also I don't think we have a way to force layout regardless of visibility yet).
amp-animation needs to invalidate the measurements on the elements it animates.
@jridgewell amp-animation runs off main thread, it can invalidate at the beginning or end of animation but not during (even if it could by running a parallel rAF loop, seems wasteful to invalidate every rAF eventhough nothing about measurements of the element may have changed - we just don't know what keyframes are doing - Passes could be running during the animation remeasuring everything we invalidated).
we should try to make force layout at beginning, invalidate measurements at end work for animation cases.
this also affects native CSS keyframe animation: https://jsbin.com/qocenunode/edit?html,output
is the recommendation to always use amp-animation?
We could take the same approach to fix both amp-animation and CSS animations by forcing layout on any targets and revalidating when animation ends. Easier to fix amp-animation than CSS however since we would need to parse and find targets in CSS.
@lannka This came up in the context of the A4A where it is higher priority to fix this. Are you planning to have a different resource manager in A4A given there is no scrolling?
@aghassemi right the problem will be gone in inabox once it has its own resource manager. but it's still a problem in general for amp-animation.
as a tmp work around, would it be acceptable to have 1px width/height with visibility=false?
I think runtime detects visibility:false. 1px width/height with opacity=0; pointer-events: none should work though.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.