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

[POC] [WIP] AMP validation fixes #878

Closed
wants to merge 14 commits into from
Closed

Conversation

ChrisBAshton
Copy link
Contributor

@ChrisBAshton ChrisBAshton commented Oct 31, 2018

Resolves #873. This PR:

The latter is the biggest change and introduces new conventions which ought to be discussed as a team.

AMP at the component level

We need to render different HTML depending on whether we're rendering the AMP page or the canonical page. This is in order for the AMP page to validate correctly.

For now, I've decided to create an amp directory inside any component which requires an AMP-specific override.

Initially, I forwarded the isAmp boolean down the rendering pipeline to the Block container, so that the component is aware of which version is needed. However, on second thoughts, an isAmp boolean is quite limited, in that we may also need to create custom modified components for other platforms in future (Facebook Instant Articles and Apple News, to name a couple). So I map isAmp to a platform string, where so far we have two possible options: amp and canonical.

#873 probably requires breaking down further, as full AMP validation & integration will involve changing lots of code. In addition to rendering different HTML at the component level, for some AMP components we will need to pull in additional AMP libraries in the <head> of the page. Plus, the Storybook integration requires some thought; currently AMP isn't pulled into the Storybook page so it is not possible to render the AMP versions of the component.

AMP validation errors

So far, this PR gets our AMP errors down from:

http://localhost:7080/news/articles/c9rpqy7pmypo.amp:1:3610 The mandatory attribute 'amp-custom' is missing in tag 'style amp-custom'. (see https://www.ampproject.org/docs/guides/author-develop/responsive/style_pages)
http://localhost:7080/news/articles/c9rpqy7pmypo.amp:53:2530 The tag 'head > style[amp-boilerplate] - old variant' appears more than once in the document. (see https://github.com/ampproject/amphtml/blob/master/spec/amp-boilerplate.md)
http://localhost:7080/news/articles/c9rpqy7pmypo.amp:55:290 The attribute 'focusable' may not appear in tag 'svg'. (see https://www.ampproject.org/docs/reference/spec#svg)
http://localhost:7080/news/articles/c9rpqy7pmypo.amp:55:3048 The tag 'img' may only appear as a descendant of tag 'noscript'. Did you mean 'amp-img'? (see https://www.ampproject.org/docs/reference/components/amp-img)
http://localhost:7080/news/articles/c9rpqy7pmypo.amp:55:4477 The tag 'img' may only appear as a descendant of tag 'noscript'. Did you mean 'amp-img'? (see https://www.ampproject.org/docs/reference/components/amp-img)
http://localhost:7080/news/articles/c9rpqy7pmypo.amp:55:5993 The tag 'img' may only appear as a descendant of tag 'noscript'. Did you mean 'amp-img'? (see https://www.ampproject.org/docs/reference/components/amp-img)
http://localhost:7080/news/articles/c9rpqy7pmypo.amp:55:7584 The tag 'img' may only appear as a descendant of tag 'noscript'. Did you mean 'amp-img'? (see https://www.ampproject.org/docs/reference/components/amp-img)
http://localhost:7080/news/articles/c9rpqy7pmypo.amp:55:8736 The tag 'img' may only appear as a descendant of tag 'noscript'. Did you mean 'amp-img'? (see https://www.ampproject.org/docs/reference/components/amp-img)
http://localhost:7080/news/articles/c9rpqy7pmypo.amp:55:10363 The attribute 'focusable' may not appear in tag 'svg'. (see https://www.ampproject.org/docs/reference/spec#svg)
http://localhost:7080/news/articles/c9rpqy7pmypo.amp:55:14676 Custom JavaScript is not allowed. (see https://www.ampproject.org/docs/reference/spec#html-tags)
http://localhost:7080/news/articles/c9rpqy7pmypo.amp:55:30418 Custom JavaScript is not allowed. (see https://www.ampproject.org/docs/reference/spec#html-tags)
http://localhost:7080/news/articles/c9rpqy7pmypo.amp:55:30542 Custom JavaScript is not allowed. (see https://www.ampproject.org/docs/reference/spec#html-tags)
http://localhost:7080/news/articles/c9rpqy7pmypo.amp:55:30666 Custom JavaScript is not allowed. (see https://www.ampproject.org/docs/reference/spec#html-tags)
http://localhost:7080/news/articles/c9rpqy7pmypo.amp:55:30790 Custom JavaScript is not allowed. (see https://www.ampproject.org/docs/reference/spec#html-tags)
http://localhost:7080/news/articles/c9rpqy7pmypo.amp:55:30921 The mandatory tag 'amphtml engine v0.js script' is missing or incorrect. (see https://www.ampproject.org/docs/reference/spec#required-markup)
http://localhost:7080/news/articles/c9rpqy7pmypo.amp:55:30921 The mandatory tag 'noscript enclosure for boilerplate' is missing or incorrect. (see https://github.com/ampproject/amphtml/blob/master/spec/amp-boilerplate.md)
http://localhost:7080/news/articles/c9rpqy7pmypo.amp:55:30921 The mandatory tag 'noscript > style[amp-boilerplate]' is missing or incorrect. (see https://github.com/ampproject/amphtml/blob/master/spec/amp-boilerplate.md)

...to:

http://localhost:7080/news/articles/c9rpqy7pmypo.amp:1:3610 The mandatory attribute 'amp-custom' is missing in tag 'style amp-custom'. (see https://www.ampproject.org/docs/guides/author-develop/responsive/style_pages)
http://localhost:7080/news/articles/c9rpqy7pmypo.amp:51:2530 The tag 'head > style[amp-boilerplate] - old variant' appears more than once in the document. (see https://github.com/ampproject/amphtml/blob/master/spec/amp-boilerplate.md)
http://localhost:7080/news/articles/c9rpqy7pmypo.amp:53:1124 The attribute 'focusable' may not appear in tag 'svg'. (see https://www.ampproject.org/docs/reference/spec#svg)
http://localhost:7080/news/articles/c9rpqy7pmypo.amp:53:11443 The attribute 'focusable' may not appear in tag 'svg'. (see https://www.ampproject.org/docs/reference/spec#svg)

The 'focusable' issue is encapsulated in #679 and is blocked on AMP-core, and the 'amp-custom' issue is encapsulated in #883 and is blocked on styled-components.

TODO:

  • Use React context to avoid passing isAmp/platform down multiple levels
  • Have the canonical and the AMP versions of the component using the same params (think "AMP first")
  • Tests added for new features
  • Test engineer approval

Copy link

@codeclimate codeclimate bot left a comment

Choose a reason for hiding this comment

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

The PR diff size of 23764 lines exceeds the maximum allowed for the inline comments feature.

Copy link

@codeclimate codeclimate bot left a comment

Choose a reason for hiding this comment

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

The PR diff size of 23764 lines exceeds the maximum allowed for the inline comments feature.

@@ -15,10 +16,14 @@ const renderCaption = captionValue =>
<Text text={captionValue} paragraphOverride={Caption} />
) : null;

const FigureContainer = ({ src, alt, ratio, copyright, caption }) => (
const FigureContainer = ({ src, alt, ratio, copyright, caption, platform }) => (
Copy link

Choose a reason for hiding this comment

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

Similar blocks of code found in 2 locations. Consider refactoring.

import { PlatformContextProvider, PlatformContextConsumer } from './index';

describe('PlatformContext', () => {
const testBrandNameWithServiceContext = platform => {
Copy link

Choose a reason for hiding this comment

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

Similar blocks of code found in 2 locations. Consider refactoring.

Fixes http://localhost:7080/news/articles/c9rpqy7pmypo.amp:55:14676 Custom JavaScript is not allowed. (see https://www.ampproject.org/docs/reference/spec#html-tags)
@ChrisBAshton ChrisBAshton changed the title [POC] [WIP] AMP components [POC] [WIP] AMP validation Nov 1, 2018
@codeclimate
Copy link

codeclimate bot commented Nov 1, 2018

Code Climate has analyzed commit 1571299 and detected 5 issues on this pull request.

Here's the issue category breakdown:

Category Count
Complexity 1
Duplication 4

The test coverage on the diff in this pull request is 100.0% (90% is the threshold).

This pull request will bring the total coverage in the repository to 96.8% (0.0% change).

View more on Code Climate.

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