Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Image Compare block in AMP when width/height are not available #17253

Conversation

westonruter
Copy link
Collaborator

Fixes #16093
See #14395

All elements in AMP need to have dimensions defined up-front so that the page will have static layout to avoid CLS (Cumulative Layout Shift). When no width or height is available for the Image Compare block, instead of omitting the width/height for the amp-image-slider component, the correct AMP fallback is to provide fallback dimensions. Since we don't know what the image dimension is, providing an aspect ratio of 1:1 seems to make sense.

Changes proposed in this Pull Request:

  • Ensure fallback dimensions are provided to Image Compare block when image size is not available

Jetpack product discussion

Does this pull request change what data or activity we track or use?

Testing instructions:

Add an Image Compare block to a post and view that post on an AMP page.

I'm not sure entirely why the width or height weren't available when calling render_amp(), so the only way I know to test this is to forcibly unset them when calling the function:

unset( $img_before['width'], $img_before['height'] );

Proposed changelog entry for your changes:

  • Fix AMP implementation of Image Compare block

@jetpackbot
Copy link

Warnings
⚠️

The PR is missing at least one [Status] label. Suggestions: [Status] In Progress, [Status] Needs Review

E2E results is available here (for debugging purposes): https://jetpack-e2e-dashboard.herokuapp.com/pr-17253

This is an automated check which relies on PULL_REQUEST_TEMPLATE. We encourage you to follow that template as it helps Jetpack maintainers do their job. If you think 'Testing instructions' or 'Proposed changelog entry' are not needed for your PR - please explain why you think so. Thanks for cooperation 🤖

Generated by 🚫 dangerJS against 667e3e1

@jeherve jeherve added AMP [Type] Bug When a feature is broken and / or not performing as intended [Status] Needs Review To request a review from Crew. Label will be renamed soon. [Pri] Normal labels Sep 24, 2020
@jeherve jeherve added this to Needs Review in AMP Compatibility Sep 24, 2020
@jeherve jeherve added this to the 9.0 milestone Sep 24, 2020
@jeherve jeherve self-assigned this Sep 24, 2020
Copy link
Member

@jeherve jeherve left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This tests well as well. 🚢

@jeherve jeherve added [Status] Ready to Merge Go ahead, you can push that green button! and removed [Status] Needs Review To request a review from Crew. Label will be renamed soon. labels Sep 24, 2020
@jeherve
Copy link
Member

jeherve commented Sep 24, 2020

r214169-wpcom

@jeherve jeherve merged commit 2b8ca7e into Automattic:master Sep 24, 2020
AMP Compatibility automation moved this from Needs Review to Done Sep 24, 2020
@matticbot matticbot added [Status] Needs Changelog and removed [Status] Ready to Merge Go ahead, you can push that green button! labels Sep 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
AMP [Pri] Normal Touches WP.com Files [Type] Bug When a feature is broken and / or not performing as intended
Projects
Development

Successfully merging this pull request may close these issues.

Image Compare Block: AMP Errors
4 participants