Amphtml: AMP Validator considers a reference to template script[type=text/plain] an error

Created on 8 Feb 2020  路  5Comments  路  Source: ampproject/amphtml

What's the issue?

When referenced from <amp-list ... template="my-template"></amp-list> to <script id="my-template" type="text/plain" template="amp-mustache"> ... </template> AMP Validator showing error "Attribute 'template' in tag 'amp-list' contains a value that does not match any other tags on the page".

However, everything will work, but the page will be deleted from Google AMP Cache due to this error.

How do we reproduce the issue?

  1. Add code to AMP page:
<amp-state id="items"><script type="application/json">[]</script></amp-state>
<button on="tap:AMP.setState({ items: items.splice(items.length, 0, items.length) })">Add item</button>
<template id="items-template" type="amp-mustache"><code>{{#.}}, {{/.}}{{.}}</code></template>
<script id="items-scripted" type="text/plain" template="amp-mustache"><code>{{#.}}, {{/.}}{{.}}</code></script>
<amp-list [src]="items" items="." layout="fixed-height" height="32" template="items-template"></amp-list>
<amp-list [src]="items" items="." layout="fixed-height" height="32" template="items-scripted"></amp-list>
  1. View the AMP page.
  2. See AMP Validator errors.

AMP Validator will point to a line with amp-list referring to the template script[type=text/plain] by id items-scripted. However, everything will work.

Source and Screenshots

Source test script: amp-mustache.html.zip

amp-mustache

Bug caching

All 5 comments

cc @ampproject/wg-caching

Sorry for the delay. Here's a minimal test case.

This requirement was added in #24267 (from http://cl/264646527); it seems it was too strict.

The solution is to add attrs { name: "id" add_value_to_set: TEMPLATE_IDS } inside the script tagspec at https://github.com/ampproject/amphtml/blob/26295bc28d43750dc7fb1550c2b1841426a7ac2b/extensions/amp-mustache/validator-amp-mustache.protoascii#L66

But first we need to make sure that all the dependents know how to find templates in script elements.

OK, fix is in master. It may take ~1 week to propagate.

@twifkak thank you very much!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sryze picture sryze  路  3Comments

torch2424 picture torch2424  路  3Comments

edhollinghurst picture edhollinghurst  路  3Comments

radiovisual picture radiovisual  路  3Comments

Download picture Download  路  3Comments