ampproject / ampproject/amp-toolbox
AMP Optimizer shouldn’t strip `sizes` without `srcset`
- Dominant language
- HTML
- Stars
- 459
- Forks
- 242
- PR merge metrics
- No merged PRs in 30d
Description
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.
Contributor guide
Research direction
Start in packages/optimizer/lib/transformers/ApplyCommonAttributes.js at lines 81-83, then read the linked AMP layout "Sizes" documentation alongside the Mozilla reference. Confirm how AMP elements use sizes without srcset in server-side rendering; done means those sizes are preserved where needed and the incorrect sizing is no longer introduced.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- html
- Domain
- web-dev
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100