Next.js: Error: Cannot read property '__html' of undefined when defining a custom Document with getInitialProps

Created on 15 Oct 2019  路  2Comments  路  Source: vercel/next.js

Bug report

Describe the bug

If you defined a pages/_document.js with getInitialProps, and return styles, you get this error when loading the app with ?amp=1 in the URL:

Error: Cannot read property '__html' of undefined when defining a custom Document.getInitialProps

To Reproduce

Use the _document.js from Material UI's example here: https://github.com/mui-org/material-ui/blob/master/examples/nextjs/pages/_document.js

The error goes away if you comment out:

    styles: [
      <React.Fragment key="styles">
        {initialProps.styles}
        {sheets.getStyleElement()}
      </React.Fragment>,
    ],

Expected behavior

An AMP response should be rendered without error.

Screenshots

System information

  • OS: macOS
  • Browser: chrome
  • Version of Next.js: 9.1.1
good first issue

Most helpful comment

All 2 comments

Going to close this issue as it hasn't had activity for a few months. I believe the issue has been fixed by Olivier 馃憤

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sospedra picture sospedra  路  3Comments

lixiaoyan picture lixiaoyan  路  3Comments

havefive picture havefive  路  3Comments

swrdfish picture swrdfish  路  3Comments

pie6k picture pie6k  路  3Comments