Total Complexity | 1 |
Complexity/F | 1 |
Lines of Code | 43 |
Function Count | 1 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | import React from "react"; |
||
2 | import Document, {Html, Head, Main, NextScript} from "next/document"; |
||
3 | import {ServerStyleSheets} from "@material-ui/core"; |
||
4 | import theme from '../src/theme'; |
||
5 | |||
6 | export default class MyDocument extends Document { |
||
7 | render(){ |
||
8 | return ( |
||
9 | <Html lang="en"> |
||
10 | <Head> |
||
11 | {/* PWA primary color */} |
||
12 | <meta name="theme-color" content={theme.palette.primary.main} /> |
||
13 | <link |
||
14 | rel="stylesheet" |
||
15 | href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap" |
||
16 | /> |
||
17 | </Head> |
||
18 | <body> |
||
19 | <Main /> |
||
20 | <NextScript /> |
||
21 | </body> |
||
22 | </Html> |
||
23 | ); |
||
24 | } |
||
25 | } |
||
26 | |||
27 | MyDocument.getInitialProps = async (ctx) => { |
||
28 | const sheets = new ServerStyleSheets(); |
||
29 | const originalRenderPage = ctx.renderPage; |
||
30 | ctx.renderPage = () => |
||
31 | originalRenderPage({ |
||
32 | enhanceApp: (App) => (props) => sheets.collect(<App {...props} />), |
||
33 | }); |
||
34 | |||
35 | const initialProps = await Document.getInitialProps(ctx); |
||
36 | |||
37 | return { |
||
38 | ...initialProps, |
||
39 | // Styles fragment is rendered after the app and page rendering finish. |
||
40 | styles: [...React.Children.toArray(initialProps.styles), sheets.getStyleElement()], |
||
41 | }; |
||
42 | } |
||
43 |