This exposes an issue that arose with the AMP plugin v2.2.2 release. In this release, there was an update to the validator spec which included, for the first time, data-hero as being a recognized attribute on img elements. Because of this, when the AMP_Noscript_Fallback::initialize_noscript_allowed_attributes() method ran in AMP_Img_Sanitzer it included data-hero among the attributes that are copied to the to the noscript > img fallback. Resulting in this change from v2.2.1 (where the data-hero attribute is now present):
Now that the noscript > img fallback has data-hero, the \AmpProject\Optimizer\Transformer\OptimizeHeroImages::findHeroImages() method in this repo incorrectly starts including both the amp-imgand the noscript > img in the list of hero images to optimize. This later causes a fatal error when the removeLazyLoading method attempts to remove any loading attribute from the noscript > img because the element was removed from the DOM by the \AmpProject\Optimizer\Transformer\OptimizeHeroImages::generateImg() method. The result is a fatal error:
Update: It also turns out that the AMP plugin shouldn't have been including the data-hero attribute on the amp-img > noscript > img fallbacks in the first place, as that is a validation error. So I've opened https://github.com/ampproject/amp-wp/pull/7036 to fix this, but still the presence of this attribute should not cause the optimizer transformer to throw a fatal error.
This exposes an issue that arose with the AMP plugin v2.2.2 release. In this release, there was an update to the validator spec which included, for the first time,
data-hero
as being a recognized attribute onimg
elements. Because of this, when theAMP_Noscript_Fallback::initialize_noscript_allowed_attributes()
method ran inAMP_Img_Sanitzer
it includeddata-hero
among the attributes that are copied to the to thenoscript > img
fallback. Resulting in this change from v2.2.1 (where thedata-hero
attribute is now present):Now that the
noscript > img
fallback hasdata-hero
, the\AmpProject\Optimizer\Transformer\OptimizeHeroImages::findHeroImages()
method in this repo incorrectly starts including both theamp-img
and thenoscript > img
in the list of hero images to optimize. This later causes a fatal error when theremoveLazyLoading
method attempts to remove anyloading
attribute from thenoscript > img
because the element was removed from the DOM by the\AmpProject\Optimizer\Transformer\OptimizeHeroImages::generateImg()
method. The result is a fatal error:So the fix is just to make sure that we skip over any element from being considered a hero if it is the child of a
noscript
element.See support topic replies.
Update: It also turns out that the AMP plugin shouldn't have been including the
data-hero
attribute on theamp-img > noscript > img
fallbacks in the first place, as that is a validation error. So I've opened https://github.com/ampproject/amp-wp/pull/7036 to fix this, but still the presence of this attribute should not cause the optimizer transformer to throw a fatal error.