-
Notifications
You must be signed in to change notification settings - Fork 384
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
Use fixed-height layout for amp-tiktok and add height estimation #6586
Conversation
Plugin builds for 1638488 are ready 🛎️!
|
Co-authored-by: Pierre Gordon <16200219+pierlon@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
// Initial height of video (most of them anyway). | ||
$height = 575; | ||
|
||
// Add the height of the metadata card with the CTA, username, and audio source. | ||
$height += 118; | ||
|
||
// Estimate the lines of text in the paragraph description (150-character limit). | ||
$p = $blockquote->getElementsByTagName( Tag::P )->item( 0 ); | ||
if ( $p instanceof Element ) { | ||
$height += 8; // Top margin. | ||
|
||
// Add height for the lines of text, where there are approx. 39 chars fit on | ||
// a line, and a line's height is 18px. | ||
$height += ceil( strlen( trim( $p->textContent ) ) / 39 ) * 18; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quite a clever way of determining the height!
Co-authored-by: Pierre Gordon <pierregordon@protonmail.com>
QA Passed Given a post with the following content: <!-- wp:embed {"url":"https://www.tiktok.com/@scout2015/video/6718335390845095173","type":"video","providerNameSlug":"tiktok","responsive":true,"align":"wide"} -->
<figure class="wp-block-embed alignwide is-type-video is-provider-tiktok wp-block-embed-tiktok"><div class="wp-block-embed__wrapper">
https://www.tiktok.com/@scout2015/video/6718335390845095173
</div></figure>
<!-- /wp:embed -->
<!-- wp:embed {"url":"https://www.tiktok.com/@deeptomcruise/video/6932166297996233989?lang=en\u0026is_copy_url=0\u0026is_from_webapp=v1\u0026sender_device=pc\u0026sender_web_id=6969641973003388422","type":"video","providerNameSlug":"tiktok","responsive":true,"align":"wide"} -->
<figure class="wp-block-embed alignwide is-type-video is-provider-tiktok wp-block-embed-tiktok"><div class="wp-block-embed__wrapper">
https://www.tiktok.com/@deeptomcruise/video/6932166297996233989?lang=en&is_copy_url=0&is_from_webapp=v1&sender_device=pc&sender_web_id=6969641973003388422
</div></figure>
<!-- /wp:embed --> It can be observed that the
|
Summary
When testing #6060 I found that there was quite a bit of layout shifting going on, even beyond what was reported in ampproject/amphtml#35789. The issue is with the
responsive
layout because as can be seen below, even whenamp-tiktok
has aresponsive
layout, the element does not resize responsively. Rather, the element has afixed-height
layout:fixed-height.mov
The problem with the
responsive
layout is that the elementsamp-tiktok
elements may start out extremely tall on wide pages before the elements initialize and their actual heights are supplied. This can result in a lot of layout shift, although not as bad as the non-AMP version still:before.mov
Therefore, this PR changes the layout of the
amp-tiktok
elements fromresponsive
tofixed-height
. Additionally, it estimates the height of the metadata card by looking at the length of the description provided in the oEmbed response. The result is much improvement to CLS even to be considered good when there are 4 instances ofamp-tiktok
on the page, with a vast improvement over the non-AMP oEmbed as provided by TikTok:after.mov
The
post_content
being shown here is as follows:Checklist