Skip to content

Commit 962a533

Browse files
committed
upgrade _document to newest version
1 parent 5d4d50b commit 962a533

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

packages/web/pages/_document.tsx

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,30 @@ interface IProps {
1111
}
1212

1313
export 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() {

0 commit comments

Comments
 (0)