question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Duplicate amp-custom

See original GitHub issue

Bug report

Describe the bug

I was working on Next.js with Netlify CMS by using withAmp().
I add <style amp-custom> in Next Head but because of using withAmp() which (likely to) auto generate <style amp-custom> with blank style.

The result is duplication of using <style amp-custom> which will failed if used AMP validator.
I try searching around about adding CSS to withAmp and changing the ‘auto added’ amp-custom style but result was no luck, plus I can’t seem to find a proper way to fix this and documentation about using withAmp properly (which is not on ‘learn’ and blog post) like: second parameter options of withAmp, does it only include { hybrid: true } ?

I can’t seem to find a good documentation of withAmp and can’t add <style amp-custom>

To Reproduce

  1. I set up a repo if you wanted to properly take a look at:
git clone -b next-amp-issue-1 https://github.com/dusit-thani-core-team/Dusit-Blog
  1. run yarn dev and go to localhost:3000, you should see there’s two <style amp-custom="">, one contains style, one doesn’t
  2. yarn export, build failed as a result of failed AMP Validator from duplication of <style amp-custom>

Expected behavior

Is there a way to reduce <style amp-custom> to one, like adding a config to remove ‘auto added’ <style amp-custom> or add style to ‘auto added’ <style amp-custom>.

Screenshots

image image

System information

  • OS: Windows 10 Tried on Chrome and Firefox.
  • Next.js 8.1.0, react: 16.8.6, react-dom: 16.8.6
  • Node 12.3.1, yarn 1.15.2

Additional context

Add any other context about the problem here. Is there a clear documentation of using AMP with CSS or using AMP or just example using similar to this?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

9reactions
rizkiandriantocommented, Aug 1, 2019

@ijjk what if I just want to use styles on some page (only on AMP page, for example)? I try to add <style> with dangerouslySetInnerHTML but still not working, I have 1 style with attribute amp-custom, but empty.

2reactions
ijjkcommented, Jun 19, 2019

Hi, you can add custom styles using a custom _document. Any styles returned in getInitialProps for _document will be combined into the one automatic style[amp-custom].

Example:

import Document from 'next/document'

export default class MyDocument extends Document {
  static async getInitialProps (ctx) {
    const initialProps = await Document.getInitialProps(ctx)
    return {
      ...initialProps,
      styles: (
        <>
          {initialProps.styles}
          <style dangerouslySetInnerHTML={{
            __html: `body{ background: orange; }`
          }} />
        </>
      )
    }
  }
}

If you are still having trouble with this feel free to reply with additional info.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Example: Restrict Duplicate Selection - amp.dev
This is a sample showing how to restrict duplicate selection of items in amp-list . This uses amp-selector in combination with amp-bind to...
Read more >
Next.JS + AMP CSS - Stack Overflow
In the console I get this error: The mandatory attribute 'amp-custom' is missing in tag 'style amp-custom (transformed)'. How can I work with ......
Read more >
Duplicate 'meta title' issue (AMP & NON-AMP Pages) - Moz
We have set the 'meta title' in desktop version & we don't want to change the title for AMP page as we have...
Read more >
Different version of amp js in HEAD - WordPress.org
Hi, I have a problem with amp generation of my article since mid may. Here is on example of “duplicates js” on HEAD...
Read more >
CUSTOM GOBO - GLASS BLACK & WHITE DUPLICATE - AMP'D ...
BLACK AND WHITE GLASS CUSTOM GOBO FOR LINE ART, LOGOS, OR TEXT. NO HALFTONES OR GRADIENTS.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found