File tree Expand file tree Collapse file tree 1 file changed +23
-6
lines changed
Expand file tree Collapse file tree 1 file changed +23
-6
lines changed Original file line number Diff line number Diff line change @@ -11,13 +11,30 @@ interface IProps {
1111}
1212
1313export default class MyDocument extends Document < IProps > {
14- public static getInitialProps ( { renderPage } : NextDocumentContext ) {
14+ public static async getInitialProps ( ctx : NextDocumentContext ) {
1515 const sheet = new ServerStyleSheet ( ) ;
16- const page = renderPage ( ( APP : any ) => ( props : any ) =>
17- sheet . collectStyles ( < APP { ...props } /> ) ,
18- ) ;
19- const styleTags = sheet . getStyleElement ( ) ;
20- return { ...page , styleTags } ;
16+ const originalRenderPage = ctx . renderPage ;
17+
18+ try {
19+ ctx . renderPage = ( ) =>
20+ originalRenderPage ( {
21+ enhanceApp : ( App : any ) => ( props : any ) =>
22+ sheet . collectStyles ( < App { ...props } /> ) ,
23+ } ) ;
24+
25+ const initialProps = await Document . getInitialProps ( ctx ) ;
26+ return {
27+ ...initialProps ,
28+ styles : (
29+ < >
30+ { initialProps . styles }
31+ { sheet . getStyleElement ( ) }
32+ </ >
33+ ) ,
34+ } ;
35+ } finally {
36+ sheet . seal ( ) ;
37+ }
2138 }
2239
2340 public render ( ) {
You can’t perform that action at this time.
0 commit comments