Duplicate "amp-custom" style tag on AMP pages
See original GitHub issueVerify canary release
- I verified that the issue exists in Next.js canary release
Provide environment information
- Operating System:
- Platform: win32
- Arch: x64
- Version: Windows 10 Home
- Binaries:
- Node: 16.14.2
- npm: N/A
- Yarn: N/A
- pnpm: N/A
- Relevant packages:
- next: 12.1.4
- react: 18.0.0
- react-dom: 18.0.0
What browser are you using? (if relevant)
Microsoft Edge 100.0.1185.39
How are you deploying your application? (if relevant)
No response
Describe the Bug
The issue is that when I generate an AMP-only page, an empty <style amp-custom></style>
is added to the head
, causing the following error after I add my own styles using raw-loader
:
/amp/[...slug] error The tag 'style amp-custom' appears more than once in the document. https://amp.dev/documentation/guides-and-tutorials/learn/spec/amphtml/#stylesheets
Expected Behavior
Next.js should add my styles to the already created style tag, or not create an empty tag when building.
To Reproduce
-
Create an AMP-only page
export const config = { amp: true };
-
Import the styles using
raw-loader
and add them to the headimport style from '!!raw-loader!@/styles/amp.css';
<style amp-custom="" dangerouslySetInnerHTML={{ __html: style }} />
-
Open the page in the browser
Issue Analytics
- State:
- Created a year ago
- Reactions:3
- Comments:6
Top GitHub Comments
@abhu-A-J , your ‘more info’ helped. Had same problem and looked into _document.tsx and it seems styles can be passed (though not 100% sure how…).
A sample: please replace ’ with (tilde)
const AmpPage = () => { return ( <> <amp-carousel>...</amp-carousel> <style jsx>{' .amp-carousel-slide { padding: 40px; } '}</style> </>) }
I used the Next.js custom document to populate the empty
<style amp-custom>
contents.For more info: https://github.com/vercel/next.js/blob/ceb07ff00c59e95b4473a945ecba566471ff0d94/packages/next/pages/_document.tsx#L825