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

Added fallback support to amp-twitter #10281

Merged
merged 1 commit into from Jul 12, 2017

Conversation

wassgha
Copy link
Contributor

@wassgha wassgha commented Jul 6, 2017

This adds the support for a fallback element inside amp-twitter that only appears when a tweet can not be loaded or was deleted.

Changes

  • Twitter iframe now emits a no-content postMessage when a tweet can't be loaded
  • amp-twitter listens to no-content and toggles the fallback accordingly
  • amp-twitter no longer shows the placeholder 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

@@ -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>&mdash; Malte Ubl (@cramforce) <a href="https://twitter.com/cramforce/status/638793490521001985">September 1, 2015</a></blockquote>
<div fallback>
Something happened..
Copy link
Member

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.

Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor

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?

  1. Show placeholder till load
  2. If load success, hide placeholder and display twitter
  3. Else if load failure,
    1. If fallback, display fallback
    2. Else if placeholder, display placeholder

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

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?

Copy link
Member

@cramforce cramforce Jul 6, 2017

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.

Copy link
Contributor

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

layout="responsive"
data-tweetid="882818033403789316"
data-cards="hidden">
<blockquote placeholder class="twitter-tweet" data-lang="en"><p lang="en" dir="ltr">AMP test</p>&mdash; Gharbi Wassim (@wassgha) <a href="https://twitter.com/wassgha/status/882818033403789316">July 6, 2017</a></blockquote>
Copy link
Member

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.

Copy link
Member

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', () => {
Copy link
Member

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);
Copy link
Member

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.

@@ -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>&mdash; Malte Ubl (@cramforce) <a href="https://twitter.com/cramforce/status/638793490521001985">September 1, 2015</a></blockquote>
<div fallback>
Something happened..
Copy link
Contributor

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?

  1. Show placeholder till load
  2. If load success, hide placeholder and display twitter
  3. Else if load failure,
    1. If fallback, display fallback
    2. 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);
Copy link
Contributor

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.

@@ -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>&mdash; Malte Ubl (@cramforce) <a href="https://twitter.com/cramforce/status/638793490521001985">September 1, 2015</a></blockquote>
<div fallback>
Copy link
Contributor

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 )

data-cards="hidden">
<blockquote placeholder class="twitter-tweet" data-lang="en"><p lang="en" dir="ltr">AMP test</p>&mdash; Gharbi Wassim (@wassgha) <a href="https://twitter.com/wassgha/status/882818033403789316">July 6, 2017</a></blockquote>
<div fallback>
Something happened..
Copy link
Contributor

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.

@wassgha
Copy link
Contributor Author

wassgha commented Jul 10, 2017

Implemented the following agreed on behavior:

  1. Show placeholder till load
  2. If load success, hide placeholder and display twitter
  3. Else if load failure,
    1. If fallback, display fallback
    2. Else if placeholder, keep placeholder
      In simple terms:
      If only placeholder is provided then use it as both a placeholder and a fallback. If both placeholder and fallback are provided, display the placeholder until load (regardless of whether there's an error or not) and use the fallback to display errors.

I have two questions about this:
1 . Is it ok that if both placeholder and fallback are provided and an error occurs, the placeholder will now be hidden?
2. Since when an error happens we don't get the resize message, the iframe's height is not set which leaves a lot of empty space when there's only a placeholder / fallback. Not sure what to set the height to since the placeholder could contain a tweet and it might actually need the space.
@cramforce

@wassgha wassgha force-pushed the twitter-fallback branch 2 times, most recently from bed3b26 to dda268b Compare July 10, 2017 00:40
@wassgha wassgha added this to the Fixit Week EOQ2 milestone Jul 10, 2017
Copy link
Member

@cramforce cramforce left a 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.

layout="responsive"
data-tweetid="882818033403789316"
data-cards="hidden">
<blockquote placeholder class="twitter-tweet" data-lang="en"><p lang="en" dir="ltr">AMP test</p>&mdash; Gharbi Wassim (@wassgha) <a href="https://twitter.com/wassgha/status/882818033403789316">July 6, 2017</a></blockquote>
Copy link
Member

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
Copy link
Member

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 :)

@aghassemi aghassemi merged commit b87b71e into ampproject:master Jul 12, 2017
this.togglePlaceholder(false);
this./*OK*/changeHeight(data['height']);
}, /* opt_is3P */true);
listenFor(iframe, 'no-content', () => {
if (this.getFallback()) {
Copy link
Contributor

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', () => {});
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants