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
Added fallback support to amp-twitter
#10281
Conversation
examples/twitter.amp.html
Outdated
@@ -20,30 +20,45 @@ | |||
layout="responsive" | |||
data-tweetid="638793490521001985"> | |||
<blockquote placeholder class="twitter-tweet" data-lang="en"><p lang="en" dir="ltr">I only needed to change some CSS. <a href="http://t.co/LvjLbjgY9F">pic.twitter.com/LvjLbjgY9F</a></p>— Malte Ubl (@cramforce) <a href="https://twitter.com/cramforce/status/638793490521001985">September 1, 2015</a></blockquote> | |||
<div fallback> | |||
Something happened.. |
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.
Please provide a better fallback text that makes clear what this is for.
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.
I think there is some confusion: Typically the placeholder is the right fallback. A very different fallback will be a super special case.
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.
What I understood from the discussion in #9355 is that the requested feature is a fallback that only appears when there's a problem (while the current behavior using a placeholder
makes the error message appear while the element is loading and persist if the error is detected or disappear if the error wasn't detected). Let's discuss this offline whenever you have time.
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.
Yeah, I understand the request, but I assume that the vast majority of publishers will want the current behavior. We should not change the behavior when no fallback is provided: Placeholder is shown when no tweet can be loaded.
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.
We could do it in stages?
- Show placeholder till load
- If load success, hide placeholder and display twitter
- Else if load failure,
- If fallback, display fallback
- Else if placeholder, display placeholder
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.
That works :) Although not what placeholder
is intended to be.. Maybe we should make a warning in the validator for publishers to switch to the correct behavior if they're not using placeholder
correctly.
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.
Archiving deleted tweets this way is actually important in the journalism space. Just because PoliticianX deletes their tweet should not mean that the article about it should no longer show the tweet content.
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.
They would be able to preserve that behavior if the text of the tweet was put inside both the fallback and the placeholder, no?
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.
We just don't want to change the behavior. As long as without a fallback the placeholder is still shown, that is fine. Definitely don't want to duplicate the markup.
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.
Agree with this. I tested with amp-img
and it tries to do the same flow as described here but is somewhat broken: created #10321
examples/twitter.amp.html
Outdated
layout="responsive" | ||
data-tweetid="882818033403789316" | ||
data-cards="hidden"> | ||
<blockquote placeholder class="twitter-tweet" data-lang="en"><p lang="en" dir="ltr">AMP test</p>— Gharbi Wassim (@wassgha) <a href="https://twitter.com/wassgha/status/882818033403789316">July 6, 2017</a></blockquote> |
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.
Can placeholder
go on the blockquote
.
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.
Lets make two examples here:
- deleted tweet (unchanged)
- deleted tweet with fallback
this./*OK*/changeHeight(data['height']); | ||
}, /* opt_is3P */true); | ||
listenFor(iframe,'no-content', () => { |
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.
Nit: space after ,
@@ -54,7 +54,8 @@ class AmpTwitter extends AMP.BaseElement { | |||
|
|||
/** @override */ | |||
firstLayoutCompleted() { | |||
// Do not hide placeholder | |||
// Hide the placeholder | |||
this.togglePlaceholder(false); |
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.
This is definitely wrong. Most will want to show the placeholder on deletion.
examples/twitter.amp.html
Outdated
@@ -20,30 +20,45 @@ | |||
layout="responsive" | |||
data-tweetid="638793490521001985"> | |||
<blockquote placeholder class="twitter-tweet" data-lang="en"><p lang="en" dir="ltr">I only needed to change some CSS. <a href="http://t.co/LvjLbjgY9F">pic.twitter.com/LvjLbjgY9F</a></p>— Malte Ubl (@cramforce) <a href="https://twitter.com/cramforce/status/638793490521001985">September 1, 2015</a></blockquote> | |||
<div fallback> | |||
Something happened.. |
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.
We could do it in stages?
- Show placeholder till load
- If load success, hide placeholder and display twitter
- Else if load failure,
- If fallback, display fallback
- Else if placeholder, display placeholder
@@ -54,7 +54,8 @@ class AmpTwitter extends AMP.BaseElement { | |||
|
|||
/** @override */ | |||
firstLayoutCompleted() { | |||
// Do not hide placeholder | |||
// Hide the placeholder | |||
this.togglePlaceholder(false); |
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.
We'd still want to wait here.
examples/twitter.amp.html
Outdated
@@ -20,30 +20,45 @@ | |||
layout="responsive" | |||
data-tweetid="638793490521001985"> | |||
<blockquote placeholder class="twitter-tweet" data-lang="en"><p lang="en" dir="ltr">I only needed to change some CSS. <a href="http://t.co/LvjLbjgY9F">pic.twitter.com/LvjLbjgY9F</a></p>— Malte Ubl (@cramforce) <a href="https://twitter.com/cramforce/status/638793490521001985">September 1, 2015</a></blockquote> | |||
<div fallback> |
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.
let's just add the fallback for a single example ( the new one you added )
examples/twitter.amp.html
Outdated
data-cards="hidden"> | ||
<blockquote placeholder class="twitter-tweet" data-lang="en"><p lang="en" dir="ltr">AMP test</p>— Gharbi Wassim (@wassgha) <a href="https://twitter.com/wassgha/status/882818033403789316">July 6, 2017</a></blockquote> | ||
<div fallback> | ||
Something happened.. |
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.
Tweet has been deleted and is no longer available.
Implemented the following agreed on behavior:
I have two questions about this: |
bed3b26
to
dda268b
Compare
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 with two small comments.
examples/twitter.amp.html
Outdated
layout="responsive" | ||
data-tweetid="882818033403789316" | ||
data-cards="hidden"> | ||
<blockquote placeholder class="twitter-tweet" data-lang="en"><p lang="en" dir="ltr">AMP test</p>— Gharbi Wassim (@wassgha) <a href="https://twitter.com/wassgha/status/882818033403789316">July 6, 2017</a></blockquote> |
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.
Lets make two examples here:
- deleted tweet (unchanged)
- deleted tweet with fallback
@@ -54,7 +54,7 @@ class AmpTwitter extends AMP.BaseElement { | |||
|
|||
/** @override */ | |||
firstLayoutCompleted() { | |||
// Do not hide placeholder | |||
// Do not hide the placeholder |
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.
nit: Please also add a period at the end of the sentence :)
dda268b
to
2fef90d
Compare
2fef90d
to
5c4f34d
Compare
this.togglePlaceholder(false); | ||
this./*OK*/changeHeight(data['height']); | ||
}, /* opt_is3P */true); | ||
listenFor(iframe, 'no-content', () => { | ||
if (this.getFallback()) { |
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.
Nit: We could check this outside the listener, to avoid creating the listener when there's no fallback:
if (this.getFallback()) {
listenFor(iframe, 'no-content', () => {});
}
This adds the support for a
fallback
element insideamp-twitter
that only appears when a tweet can not be loaded or was deleted.Changes
no-content
postMessage
when a tweet can't be loadedamp-twitter
listens tono-content
and toggles the fallback accordinglyamp-twitter
no longer shows theplaceholder
when a tweet can't be loaded (now as soon as the tweet finished retrieving, the placeholder is hidden regardless of whether the tweet was found or not)Closes #9355 , Related-to https://stackoverflow.com/questions/43975240/amp-twitter-fallback-when-tweet-deleted