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

AmpCarousel 0.2 "attribute 'version' may not appear" #45

Open
mo-hh234 opened this issue Sep 25, 2019 · 2 comments
Open

AmpCarousel 0.2 "attribute 'version' may not appear" #45

mo-hh234 opened this issue Sep 25, 2019 · 2 comments

Comments

@mo-hh234
Copy link

mo-hh234 commented Sep 25, 2019

Hey,
when passing version "0.2" to AmpCarousel. I get errors from the AMP Validation Service:

The attribute 'version' may not appear in tag 'AMP-CAROUSEL'.

At the same time im passing version "0.1" to an Amp-Carousel [lighbox]

The attribute 'version' may not appear in tag 'AMP-CAROUSEL lightbox'.

<AmpCarousel version="0.2" ... />

Is there a workaround?

At the same Time i want to use amp-carousel 0.2 but amp-lighbox-gallery 0.1

It seems that this is not possible.

When i set version to 0.2 on the normal AmpCarousel, and 0.1 on the AmpCarousel[lighbox]. The ScriptManager injects

<script async="" custom-element="amp-carousel" src="https://cdn.ampproject.org/v0/amp-carousel-0.1.js"></script>
<script async="" custom-element="amp-lightbox-gallery" src="https://cdn.ampproject.org/v0/amp-lightbox-gallery-0.1.js"></script>

If i set AmpCarousel[lighbox] to 0.2 the correct "amp-carousel" script gets injected. But i get the following AMP Validation Error:

The attribute 'src' in tag 'amp-lightbox-gallery extension .js script' is set to the invalid value 'https://cdn.ampproject.org/v0/amp-lightbox-gallery-0.2.js'.

@dfrankland
Copy link
Owner

dfrankland commented Sep 26, 2019

Hmmm, perhaps I we need to update the amphtml-validator-rules and re-run the code generation.

@mo-hh234
Copy link
Author

mo-hh234 commented Oct 2, 2019

Rerun Code Gerneration does not work.

My workaround is

export default class MyDocument extends Document {
  static async getInitialProps(
    ctx: DocumentContext
  ): Promise<AmpReactDocumentInitialProps> {
    const ampScripts = new AmpScripts();
    const page = await ctx.renderPage(App => props =>
        <AmpScriptsManager ampScripts={ampScripts}>
          <App {...props} />
        </AmpScriptsManager>
    );
    ampScripts.getScripts().forEach(({ extension }) => { // Workaround for https://github.com/dfrankland/react-amphtml/issues/45
      if (extension === "amp-carousel") {
        ampScripts.addExtension({
          extension: "amp-carousel",
          version: "0.2"
        });
      }
      if (extension === "amp-lightbox-gallery") {
        ampScripts.addExtension({
          extension: "amp-lightbox-gallery",
          version: "0.1"
        });
      }
    });
    return {
      ...page,
      ampScriptTags: ampScripts.getScriptElements()
    };
  }

  render() {
    const props = this.props;
    return (
      <Html lang="de">
        <Head>
          {props.ampScriptTags}
        </Head>
        <body>
          <Main />
        </body>
      </Html>
    );
  }
}

I looked into the code and amp-carousel used with lightbox always loads the same version for carousel and lighbox-gallery.

contextHelper({ context, extension: "amp-carousel", version: props.version });

  contextHelper({
    context,
    extension: "amp-lightbox-gallery",
    version: props.version
  });

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

No branches or pull requests

2 participants