amp-toolbox icon indicating copy to clipboard operation
amp-toolbox copied to clipboard

AMP Optimizer shouldn’t strip `sizes` without `srcset`

Open chasefinch opened this issue 5 years ago • 1 comments

In packages/optimizer/lib/transformers/ApplyCommonAttributes.js line 81-83, the optimizer strips the sizes attribute when srcset is not also present. Here is the related comment in the code::

// According to the Mozilla docs, a sizes attribute without a valid srcset attribute should have no effect. // Therefore, it should simply be stripped, without producing media queries. // @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img#attr-sizes

But for AMP elements, sizes has a bigger meaning; see "Sizes" on https://amp.dev/documentation/guides-and-tutorials/learn/amp-html-layout/?format=websites

Stripping it causes some amp elements to size incorrectly after server-side-rendering is applied.

chasefinch avatar Aug 26 '20 17:08 chasefinch

Good point! We should fix this!

sebastianbenz avatar Aug 26 '20 17:08 sebastianbenz