Skip to content

Commit

Permalink
Merge pull request #516 from ampproject/fix/find-hero-images
Browse files Browse the repository at this point in the history
  • Loading branch information
schlessera authored Apr 8, 2022
2 parents 26efcaa + 7f87d15 commit f6c3daf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Optimizer/Transformer/OptimizeHeroImages.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,11 @@ private function findHeroImages(Document $document, $maxHeroImageCount)
$node = $document->body;

while ($node !== null) {
if (! $node instanceof Element) {
if (
! $node instanceof Element
||
( $node->parentNode instanceof Element && $node->parentNode->tagName === Tag::NOSCRIPT )
) {
$node = NodeWalker::nextNode($node);
continue;
}
Expand Down
9 changes: 9 additions & 0 deletions tests/Optimizer/Transformer/OptimizeHeroImagesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,15 @@ public function dataTransform()
),
],

'hero image with noscript fallback' => [
$input(
'<amp-img data-hero width="500" height="400" src="/img1.png"><noscript><img data-hero width="500" height="400" src="/img1.png"></noscript></amp-img>'
),
$output(
'<amp-img data-hero height="400" i-amphtml-ssr src="/img1.png" width="500"><img class="i-amphtml-fill-content i-amphtml-replaced-content" decoding="async" src="/img1.png"></amp-img>'
),
],

'superfluous candidates are ignored without throwing an error' => [
$input(
'<amp-img width="500" height="400" src="/foo.png"></amp-img>'
Expand Down

0 comments on commit f6c3daf

Please sign in to comment.