parent
8902100baa
commit
309731fe1b
4 changed files with 49 additions and 17 deletions
@ -1,3 +1,12 @@ |
||||
{ |
||||
"extends": ["next", "next/core-web-vitals", "prettier"] |
||||
"extends": [ |
||||
"next", |
||||
"next/core-web-vitals", |
||||
"prettier" |
||||
], |
||||
"rules": { |
||||
"@next/next/no-img-element": [ |
||||
"off" |
||||
] |
||||
} |
||||
} |
||||
|
@ -0,0 +1,29 @@ |
||||
import Document, { DocumentContext } from 'next/document'; |
||||
import { ServerStyleSheet } from 'styled-components'; |
||||
|
||||
export default class MyDocument extends Document { |
||||
static async getInitialProps(ctx: DocumentContext) { |
||||
const sheet = new ServerStyleSheet(); |
||||
const originalRenderPage = ctx.renderPage; |
||||
|
||||
try { |
||||
ctx.renderPage = () => originalRenderPage({ |
||||
enhanceApp: (App) => (props) => |
||||
sheet.collectStyles(<App {...props} />) |
||||
}); |
||||
|
||||
const initialProps = await Document.getInitialProps(ctx); |
||||
return { |
||||
...initialProps, |
||||
styles: ( |
||||
<> |
||||
{initialProps.styles} |
||||
{sheet.getStyleElement()} |
||||
</> |
||||
) |
||||
}; |
||||
} finally { |
||||
sheet.seal(); |
||||
} |
||||
} |
||||
} |
After Width: | Height: | Size: 749 KiB |
Loading…
Reference in new issue