Skip to content

Commit f6c3daf

Browse files
authored
Merge pull request #516 from ampproject/fix/find-hero-images
2 parents 26efcaa + 7f87d15 commit f6c3daf

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/Optimizer/Transformer/OptimizeHeroImages.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,11 @@ private function findHeroImages(Document $document, $maxHeroImageCount)
202202
$node = $document->body;
203203

204204
while ($node !== null) {
205-
if (! $node instanceof Element) {
205+
if (
206+
! $node instanceof Element
207+
||
208+
( $node->parentNode instanceof Element && $node->parentNode->tagName === Tag::NOSCRIPT )
209+
) {
206210
$node = NodeWalker::nextNode($node);
207211
continue;
208212
}

tests/Optimizer/Transformer/OptimizeHeroImagesTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,15 @@ public function dataTransform()
249249
),
250250
],
251251

252+
'hero image with noscript fallback' => [
253+
$input(
254+
'<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>'
255+
),
256+
$output(
257+
'<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>'
258+
),
259+
],
260+
252261
'superfluous candidates are ignored without throwing an error' => [
253262
$input(
254263
'<amp-img width="500" height="400" src="/foo.png"></amp-img>'

0 commit comments

Comments
 (0)