ampproject / ampproject/amphtml

amp-img won't render when nested in a hidden element

Open
#34,059 6 comments 0 reactions 0 assignees View on GitHub
Component: amp-img Stale Type: Bug WG: components
Dominant language
JavaScript
Stars
14.9k
Forks
4.1k
PR merge metrics
No merged PRs in 30d

Description

If you have a bug for AMP please fill in the following template. Delete everything except the headers (including this text).

## What's the issue?
amp-img won't render

## How do we reproduce the issue?

Try the following example on the playground https://playground.amp.dev/amp/

```


My AMP Page


body {
-webkit-animation: -amp-start 8s steps(1, end) 0s 1 normal both;
-moz-animation: -amp-start 8s steps(1, end) 0s 1 normal both;
-ms-animation: -amp-start 8s steps(1, end) 0s 1 normal both;
animation: -amp-start 8s steps(1, end) 0s 1 normal both
}

@-webkit-keyframes -amp-start {
from {
visibility: hidden
}
to {
visibility: visible
}
}

@-moz-keyframes -amp-start {
from {
visibility: hidden
}
to {
visibility: visible
}
}

@-ms-keyframes -amp-start {
from {
visibility: hidden
}
to {
visibility: visible
}
}

@-o-keyframes -amp-start {
from {
visibility: hidden
}
to {
visibility: visible
}
}

@keyframes -amp-start {
from {
visibility: hidden
}
to {
visibility: visible
}
}

body {
-webkit-animation: none;
-moz-animation: none;
-ms-animation: none;
animation: none
}











.hidden {
display: none
}

#myinput:checked + .hidden {
display: block
}

MyInput

```

Please provide a public URL and ideally a reduced test case (e.g. on jsbin.com) that exhibits only your issue and nothing else. Provide step-by-step instructions for reproducing the issue:

1. Here we have a deeply nested amp-img in an initially hidden div.
2. When clicking on the checkbox the div will become visible, but the amp-img won't load or it will load randomly.

![image](https://user-images.githubusercontent.com/20220341/116440622-5ebe0800-a859-11eb-86f9-e283e6cdcc07.png)

## What browsers are affected?

I've tried on firefox / chrome and get consistent behaviour in the playground

## Which AMP version is affected?

Powered by AMP ⚡ HTML – Version 2104170104001

Contributor guide

Open the contributing guide

Research direction

Reproduce the nested amp-img case in the AMP Playground using the provided HTML and checkbox steps, then trace the amp-img behavior when its parent changes from display:none to visible. Done means the image renders consistently after the hidden container is revealed in Firefox and Chrome.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.