This repository was archived by the owner on Nov 8, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +17
-12
lines changed Expand file tree Collapse file tree 1 file changed +17
-12
lines changed Original file line number Diff line number Diff line change @@ -3,22 +3,27 @@ import { ServerStyleSheet } from 'styled-components'
33
44/* eslint-disable */
55export default class MyDocument extends Document {
6- static getInitialProps ( { renderPage } ) {
6+ static async getInitialProps ( ctx ) {
77 const sheet = new ServerStyleSheet ( )
8- const page = renderPage ( App => props =>
9- sheet . collectStyles ( < App { ...props } /> )
10- )
11- const styleTags = sheet . getStyleElement ( )
12- return { ...page , styleTags }
8+ const originalRenderPage = ctx . renderPage
9+
10+ try {
11+ ctx . renderPage = ( ) =>
12+ originalRenderPage ( {
13+ enhanceApp : App => props => sheet . collectStyles ( < App { ...props } /> ) ,
14+ } )
15+
16+ const initialProps = await Document . getInitialProps ( ctx )
17+ return {
18+ ...initialProps ,
19+ styles : [ ...initialProps . styles , ...sheet . getStyleElement ( ) ] ,
20+ }
21+ } finally {
22+ sheet . seal ( )
23+ }
1324 }
1425
1526 render ( ) {
16- /*
17- const sheet = new ServerStyleSheet()
18- const main = sheet.collectStyles(<Main />)
19- const styleTags = sheet.getStyleElement()
20- */
21-
2227 return (
2328 < html >
2429 < Head >
You can’t perform that action at this time.
0 commit comments