amphtml icon indicating copy to clipboard operation
amphtml copied to clipboard

<amp-*> </amp-*> don't use contents as fallback

Open kevinmarks opened this issue 11 years ago • 32 comments

specifically

<amp-twitter width=390 height=50
    layout="responsive"
    data-tweetid="651787425052692481">
<blockquote class="twitter-tweet" data-conversation="none" lang="en">
<p lang="en" dir="ltr">
<a href="https://twitter.com/kevinmarks">@kevinmarks</a> a documentation bug! Will fix immediately. Related Github issue 
<a href="https://t.co/J8Kglgh2ki">https://t.co/J8Kglgh2ki</a></p>
&mdash; Malte Ubl (@cramforce) <a href="https://twitter.com/cramforce/status/651787425052692481">October 7, 2015</a></blockquote>
</amp-twitter>

displays the blockquote fallback under the decorated tweet.

Why not just support the same blockquote markup as using

<script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script> 

does?

kevinmarks avatar Oct 07 '15 23:10 kevinmarks

Should work if you put a placeholder attribute on the blockquote element (We support the placeholder attribute on all custom element children).

We could introduce some special cases.

In general placeholder content has to adhere to the same sizing constraints as all content to avoid visual jank.

cramforce avatar Oct 07 '15 23:10 cramforce

As a general explanation: AMP will render a placeholder before it even knows what amp-twitter is (which loads asynchronously), so we need a generic way to find the placeholder content. Since some custom elements use some of their children we cannot just go and use all of them as placeholders.

cramforce avatar Oct 08 '15 00:10 cramforce

Thanks Kevin.

I'm giving this a fair amount of thought because for our Twitter case especially the fallback content is vitally important. News articles are written about Tweets and they're dependent on the text for context. The widgets are usually content not decoration, so if a Tweet is deleted (or Twitter were to be down at render time, or blocked in the viewer's country) it's important that the article still make sense, even if not rendered as an all-singing, all-dancing widget.

In general for components we need to think about both how to provide placeholder or fallback content, but also where the author is going to get it from. If it adds too much overhead to a writer or editor's workflow it won't get used and article robustness and quality will suffer. In Twitter's case we have a standard oembed API that returns the blockquote embed code above, which is usually what's pasted into content editors or pulled in by the CMS from a URL. It might be optimal for writers if an <amp- tag could be wrapped around that.

There's also the proposed Web Component is attribute, which I know is sitting unadopted by browser vendors at present, but would also work very gracefully with the existing code:

<blockquote class="twitter-tweet" is="amp-tweet">…</blockquote>

There's a lot of different ways we could go, and I'm looking forward to taking some time to explore them as we develop AMP.

Ben

BenWard avatar Oct 08 '15 05:10 BenWard

@BenWard unfortunately the is="" part of the specification didn't make it for Custom Elements v1 and vendors are still discussing if it's worth the hassle (it is in my opinion).

For consistency sake though it's easier to also explain <amp- tags without having dual behavior through the is attribute.

If I might suggest a possible workaround for this case, the rule ~~amp-twitter.-amp-element > blockquote { display: none; } should do a reasonable job.~~ actually you cannot use directly -amp- prefix so this is the workaround:

<style amp-custom>amp-twitter > * + blockquote { display: none; }</style>

Hacky and dirty but this passed the validation and worked as expected.

WebReflection avatar Oct 08 '15 06:10 WebReflection

How about we use the "placeholder" system for this? It's still a bit new, but I think it could work very well here. E.g.:

<amp-twitter ...> 
  <blockquote placeholder>
  </blockquote>
</amp-twitter>

It currently requires the child to have a placeholder attribute. The placeholder elements are shown in the "unresolved" and "unbuilt" states automatically. Basically, placeholders are kept around and displayed until the element itself is ready to hide it. It's currently supported in amp-anim element, but the idea is to extend this support to all elements and we should be almost there.

dvoytenko avatar Oct 08 '15 18:10 dvoytenko

what if the fallback is an input with a placeholder which means ... actually, the input placeholder?

WebReflection avatar Oct 09 '15 01:10 WebReflection

This is a very specific use of a placeholder attribute. Only direct children of AMP elements are considered for a placeholder. If there has to be an input with a placeholder attribute positioned inside the AMP element, it'd be easy enough to wrap it in a div. But it's rather unlikely that someone would want to put an input inside a amp-video or a amp-twitter tag. The ergonomics of placeholder attribute and consistency, however, were a rather good trade-off.

dvoytenko avatar Oct 09 '15 02:10 dvoytenko

I'm looking at the custom elements spec and I can't find any mention of a placeholder attribute (which, as others have pointed out, is an already existing attribute on form fields).

@dvoytenko or @cramforce Could either of you point me to some existing documentation for this placeholder attribute? Or is this something that has been invented for AMP? (and if it's the latter, why not use some existing extension mechanism such as the class or data- attribute?)

adactio avatar Oct 10 '15 18:10 adactio

Placeholder is an AMP concept. We are currently working to make it more generic and upgrade it to be in the main spec as opposed to documented per element.

We use non-data- attribute for framework attribute because data- attributes are reserved for the application and extended element configuration.

You could argue for amp-placeholder but that looks noisy.

We generally reserve the right to use bare attributes in AMP. That seems to be in idiomatic in the web components world. Disagreement should be uttered there. We just follow precedent because we want to be good citizens. On Oct 10, 2015 11:45 AM, "Jeremy Keith" [email protected] wrote:

I'm looking at the custom elements spec http://w3c.github.io/webcomponents/spec/custom/ and I can't find any mention of a placeholder attribute (which, as others have pointed out, is an already existing attribute on form fields).

@dvoytenko https://github.com/dvoytenko or @cramforce https://github.com/cramforce Could either of you point me to some existing documentation for this placeholder attribute? Or is this something that has been invented for AMP? (and if it's the latter, why not use some existing extension mechanism such as the class or data- attribute?)

— Reply to this email directly or view it on GitHub https://github.com/ampproject/amphtml/issues/517#issuecomment-147115586.

cramforce avatar Oct 10 '15 19:10 cramforce

Riiiiiight. You just make up attributes. Attributes that already exist in other contexts in HTML. :-/

Um. At some point, you may have to stop referring to AMP HTML as a subset of HTML and just say it's a different language, because, well, if you invent attributes like this, it is.

We just follow precedent because we want to be good citizens.

I suggest using HTML's existing mechanisms for extension if you plan on being good citizens. You've rejected data- attributes, saying:

We use non-data- attribute for framework attribute because data- attributes are reserved for the application and extended element configuration.

...but what you are doing is extended element configuration. That is exactly what you are doing.

At the very least, you could use class="placeholder".

We generally reserve the right to use bare attributes in AMP. That seems to be in idiomatic in the web components world. Disagreement should be uttered there.

Citation needed.

adactio avatar Oct 10 '15 22:10 adactio

You can absolutely make up attributes. We've been able to do that in HTML since parsers were forgiving which, it turns out, is roughly forever. Attributes are a contextual grammar: they have meaning in the context of the elements for which they're supported. Some attributes are common (e.g. id) across all HTMLElement subclass instances. Others are more local.

So it has always been. Nothing to see here.

slightlyoff avatar Oct 10 '15 22:10 slightlyoff

But placeholder already exists as an attribute in HTML, Alex.

adactio avatar Oct 10 '15 22:10 adactio

It's contextual to <input>. It isn't in the root of the inheritance hierarchy. It can have other definitions in other contexts.

Maybe this isn't wise, but it clearly isn't verboten for any other reason.

slightlyoff avatar Oct 10 '15 22:10 slightlyoff

This is precisely the use-case for which data- attributes exist. A data-placeholder attribute would be far better in this situation: the placeholder is used by browsers (in form fields), while data- attributes are there specifically to be used by scripts like https://cdn.ampproject.org/v0.js

adactio avatar Oct 10 '15 22:10 adactio

Data- is for apps. We use unprefixed names to avoid conflicts with them. E.g. they are used to configure embeds.

This will not change until maybe in version 2.0 when we found out in practice that we have a problem.

We can open another bug to rename placeholder to something else like "instead" or "until-loaded" or whatever. But we will not stop attaching semantics to custom attribute names for the time being. On Oct 10, 2015 3:22 PM, "Jeremy Keith" [email protected] wrote:

This is precisely the use-case for which data- attributes exist. A data-placeholder attribute would be far better in this situation: the placeholder is used by browsers (in form fields), while data- attributes are there specifically to be used by scripts like https://cdn.ampproject.org/v0.js

— Reply to this email directly or view it on GitHub https://github.com/ampproject/amphtml/issues/517#issuecomment-147130350.

cramforce avatar Oct 10 '15 23:10 cramforce

You are an app. You don't work unless your js is included, and your required markup is actively hostile to pages working on their own.

kevinmarks avatar Oct 11 '15 00:10 kevinmarks

I will talk to the polymer team. If they figured out their decisions were bad I'll change my mind.

Kevin: in AMP no other JS could conflict. Only future extensions to HTML and arguments to extended components. On Oct 10, 2015 5:20 PM, "Kevin Marks" [email protected] wrote:

You are an app. You don't work unless your js is included, and your required markup is actively hostile to pages working on their own.

— Reply to this email directly or view it on GitHub https://github.com/ampproject/amphtml/issues/517#issuecomment-147140707.

cramforce avatar Oct 11 '15 00:10 cramforce

Data- is for apps.

Whaa..? Where did this come from? And what's the definition of an app?

I'm guessing that something that requires JavaScript in order to parse custom elements in order to display an image leans heavily towards the app end of the spectrum.

You understand that because AMP HTML bans any JavaScript other than its own, there's literally no way that a data- attribute could possibly conflict with anything ("in AMP no other JS could conflict") but then say "Only future extensions to HTML" ...like, what? HTML gaining a placeholder attribute? Which it already has?

That's exactly the reason why it's safer not to create new attributes willy-nilly.

Be conservative in what you send.

adactio avatar Oct 11 '15 00:10 adactio

If nothing else, how about having a consistent coding style? You've currently got the attribute amp-custom on the style element ...but plain ol' placeholder on other elements. If you're going to mint attributes, how about making them consistent by always having a prefix of amp-:

  • amp-custom
  • amp-placeholder
  • amp-layout
  • amp-type
  • amp-shortcode

adactio avatar Oct 11 '15 10:10 adactio

Jeremy and Keith, taking with html spec people and our users we found that out attribute semantics are both clear and proper. They also have good ergonomics. Do you have a good argument why we should change it? We found that there's no concern of conflicts with input's placeholders. And there's nothing "data" about these attributes. Also please note that we are getting rid of "amp-custom" as well.

-d On Oct 11, 2015 3:59 AM, "Jeremy Keith" [email protected] wrote:

If nothing else, how about having a consistent coding style? You've currently got the attribute amp-custom on the style element ...but plain ol' placeholder on other elements. If you're going to mint attributes, how about making them consistent by always having a prefix of amp-:

  • amp-custom
  • amp-placeholder
  • amp-layout
  • amp-type
  • amp-shortcode

— Reply to this email directly or view it on GitHub https://github.com/ampproject/amphtml/issues/517#issuecomment-147181255.

You received this message because you are subscribed to the Google Groups "amphtml-eng-github" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/a/google.com/d/msgid/amphtml-eng-github/ampproject/amphtml/issues/517/147181255%40github.com https://groups.google.com/a/google.com/d/msgid/amphtml-eng-github/ampproject/amphtml/issues/517/147181255%40github.com?utm_medium=email&utm_source=footer .

You received this message because you are subscribed to the Google Groups "amphtml-eng" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/a/google.com/d/msgid/amphtml-eng/ampproject/amphtml/issues/517/147181255%40github.com https://groups.google.com/a/google.com/d/msgid/amphtml-eng/ampproject/amphtml/issues/517/147181255%40github.com?utm_medium=email&utm_source=footer .

amphtml-team avatar Oct 11 '15 19:10 amphtml-team