-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
Bento: iframe components attemptChangeHeight
#35027
Bento: iframe components attemptChangeHeight
#35027
Conversation
As per #34948 (comment):
|
I just encountered an issue with requiring static sizing up-front for embeds. With Twitter, for example, tweets will have different heights depending on the viewport. On mobile, a tweet may be 500px high but on desktop it may be 630px high. If this tweet is in the first viewport where automatic height changes will not be allowed, the only way I can think of this can be accommodated is to require authors to add multiple tweet embeds for each breakpoint, for example: <amp-twitter class="mobile" media="(max-width: 360px)" height="500" layout="fixed-height" width="auto" data-tweetid="1405578489554743296"></amp-twitter>
<amp-twitter class="desktop" media="(min-width: 361px)" height="630" layout="fixed-height" width="auto" data-tweetid="1405578489554743296"></amp-twitter> This seems like a heavy lift for developers and a poor DX. For more, see ampproject/amp-wp#4729 (comment). |
@westonruter I will exclude |
@westonruter Thank you for clarifying that some providers may have different or no solutions for resolving dimensions predictably and statically, and that it can be burdensome for developers to meet these needs without clear support or guidance. Given the examples for
And these follow up steps:
|
@caroqliu yeah, merging with these additional changes sounds good to me. |
1776293
to
fe25fea
Compare
src/preact/base-element.js
Outdated
/** @override */ | ||
attemptChangeHeight(newHeight) { | ||
super.attemptChangeHeight(newHeight).catch(() => { | ||
if (!this.getOverflowElement()) { |
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.
For auto-envelope.
if (!this.getOverflowElement()) { | |
if (this.getOverflowElement && !this.getOverflowElement()) { |
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.
Good catch, thank you!
src/preact/base-element.js
Outdated
user().warn( | ||
TAG, | ||
'[overflow] element not found. Provide one to enable resizing to full contents.' | ||
); |
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.
As you mentioned offline, we might want to use console.warn
instead.
I've done some more experimentation with obtaining sizes of an embed up-front and then serving multiple It would be better if |
attemptChangeHeight
is preferred toforceChangeHeight
for increased CLS compliance as the default. This PR also includes documentation regarding resize recommendations for publishers. Related to #34969cc @westonruter