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

✨ Validator support for transformed intrinsic layout #24119

Merged
merged 4 commits into from
Dec 17, 2019

Conversation

sebastianbenz
Copy link
Contributor

Intrinsic layout SSR adds the following sizer element:

<amp-img height="100" width="300" layout="intrinsic" class="i-amphtml-layout-intrinsic i-amphtml-layout-size-defined" i-amphtml-layout="intrinsic">
  <i-amphtml-sizer class="i-amphtml-sizer">
    <img alt="" aria-hidden="true" class="i-amphtml-intrinsic-sizer" role="presentation" src="data:image/svg+xml;charset=utf-8,<svg height=&quot;100&quot; width=&quot;300&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; version=&quot;1.1&quot;/>">
  </i-amphtml-sizer>
</amp-img>

This commit extends the i-amphtml-sizer validation rules to
alternatively support the intrinsic sizer element. The SVG sizer image
is validated via a regex checking if the src value is an SVG.

validator/validator-main.protoascii Outdated Show resolved Hide resolved
validator/validator-main.protoascii Outdated Show resolved Hide resolved
mandatory_parent: "I-AMPHTML-SIZER"
attrs: {
name: "class"
value_regex: "i-amphtml-intrinsic-sizer"
Copy link
Member

@Gregable Gregable Aug 21, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this just be value:?

Note that in validation rules, value_regex always means full match and blacklisted_value_regex is partial match. This is a bit confusing, but it is in place to avoid mistakes in the wrong direction (looser validation rules than expected).

If you intended partial match, use ".*i-amphtml-intrinsic-sizer.*" and also ignore my dispatch key comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First I had it as value, but that caused the test to fail. I couldn't work out why. I assumed that was specific to how class is handled:

    |      <i-amphtml-sizer class="i-amphtml-sizer"><img alt="" aria-hidden="true" class="i-amphtml-intrinsic-sizer" role="presentation" src="data:image/svg+xml;charset=utf-8,<svg height=&quot;100&quot; width=&quot;300&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; version=&quot;1.1&quot;/>"></i-amphtml-sizer>
    >>                                              ^~~~~~~~~
    transformed_feature_tests/server_side_rendering.html:40:45 The mandatory attribute 'class' is missing in tag 'IMG-I-AMPHTML-INTRINSIC-SIZER'. [DISALLOWED_HTML]

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thats odd. Is the example you give the result for that test? Did you verify the spelling?

validator/validator-main.protoascii Show resolved Hide resolved
validator/validator-main.protoascii Outdated Show resolved Hide resolved
validator/validator-main.protoascii Outdated Show resolved Hide resolved
Copy link
Contributor Author

@sebastianbenz sebastianbenz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Finally had some time to look into this again. I've addressed the comments. The current version:

  • passes the tests
  • accepts the intrinsic layout sizer

However, theoretically there are still a few validation rules possible:

  • ensure that sizer matches layout, e.g. currently it'd be valid for the responsive sizer to have an img child.
  • ensure that the class attribute is set for the intrinsic sizer: <i-amphtml-sizer class="i-amphtml-sizer">

I'd need some guidance though on how to best implement these in the validator (in particular how to figure out from a child ndoe whether one of the parent nodes has a specific attribute value set).

Copy link
Contributor Author

@sebastianbenz sebastianbenz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've split i-amphtml-sizer into two tag specs. Now, sizer attributes area correctly verified. I couldn't figure out though how to set I-AMPHTML-SIZER-INTRINSIC as the mandatory parent.

PTAL

validator/validator-main.protoascii Show resolved Hide resolved
validator/validator-main.protoascii Outdated Show resolved Hide resolved
validator/engine/validator.js Show resolved Hide resolved
@amp-owners-bot
Copy link

Hey @ampproject/wg-caching, these files were changed:

  • validator/validator-main.protoascii

@Gregable
Copy link
Member

The amp-owners-bot popped this back to my visibility. What's the latest status on this? Do you need additional review?

Intrinsic layout SSR adds the following sizer element:

```html
<amp-img height="100" width="300" layout="intrinsic" class="i-amphtml-layout-intrinsic i-amphtml-layout-size-defined" i-amphtml-layout="intrinsic">
  <i-amphtml-sizer class="i-amphtml-sizer">
    <img alt="" aria-hidden="true" class="i-amphtml-intrinsic-sizer" role="presentation" src="data:image/svg+xml;charset=utf-8,<svg height=&quot;100&quot; width=&quot;300&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; version=&quot;1.1&quot;/>">
  </i-amphtml-sizer>
</amp-img>
```

This commit extends the `i-amphtml-sizer` validation rules to
alternatively support the intrinsic sizer element. The SVG sizer image
is validated via a regex checking if the `src` value is an SVG.
Copy link
Contributor Author

@sebastianbenz sebastianbenz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated the PR to add the missing check for the intrinsic parent (now that b/139869098 has landed). PTAL

validator/validator-main.protoascii Outdated Show resolved Hide resolved
@Gregable
Copy link
Member

Looks good to me. @honeybadgerdontcare did you have any other requirements? When ready, please approve.

Copy link
Contributor

@honeybadgerdontcare honeybadgerdontcare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm after nit addressed

validator/validator-main.protoascii Show resolved Hide resolved
@sebastianbenz sebastianbenz merged commit 686791f into ampproject:master Dec 17, 2019
@sebastianbenz sebastianbenz deleted the ssr-intrinsic branch December 17, 2019 21:15
honeybadgerdontcare added a commit that referenced this pull request Dec 18, 2019
* cl/286094937 Allow validator to support LTS release channel for runtime and extensions

* cl/286215939 Revision bump for #24119

* exempt validator engine
micajuine-ho pushed a commit to micajuine-ho/amphtml that referenced this pull request Dec 27, 2019
Validator support for transformed intrinsic layout

Intrinsic layout SSR adds the following sizer element:

```html
<amp-img height="100" width="300" layout="intrinsic" class="i-amphtml-layout-intrinsic i-amphtml-layout-size-defined" i-amphtml-layout="intrinsic">
  <i-amphtml-sizer class="i-amphtml-sizer">
    <img alt="" aria-hidden="true" class="i-amphtml-intrinsic-sizer" role="presentation" src="data:image/svg+xml;charset=utf-8,<svg height=&quot;100&quot; width=&quot;300&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; version=&quot;1.1&quot;/>">
  </i-amphtml-sizer>
</amp-img>
```

This commit extends the `i-amphtml-sizer` validation rules to
alternatively support the intrinsic sizer element. The SVG sizer image
is validated via a regex checking if the `src` value is an SVG.
micajuine-ho pushed a commit to micajuine-ho/amphtml that referenced this pull request Dec 27, 2019
* cl/286094937 Allow validator to support LTS release channel for runtime and extensions

* cl/286215939 Revision bump for ampproject#24119

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

Successfully merging this pull request may close these issues.

4 participants