Permalink
material-ui/examples/nextjs/pages/_document.js
Newer
100644
85 lines (79 sloc)
2.17 KB
2
import Document, { Head, Main, NextScript } from 'next/document';
4
import flush from 'styled-jsx/server';
13
<Head>
14
<title>My page</title>
15
<meta charSet="utf-8" />
16
{/* Use minimum-scale=1 to enable GPU rasterization */}
17
<meta
18
name="viewport"
19
content={
20
'user-scalable=0, initial-scale=1, ' +
21
'minimum-scale=1, width=device-width, height=device-height'
22
}
23
/>
24
{/* PWA primary color */}
25
<meta name="theme-color" content={pageContext.theme.palette.primary.main} />
26
<link
27
rel="stylesheet"
28
href="https://fonts.googleapis.com/css?family=Roboto:300,400,500"
29
/>
30
</Head>
31
<body>
32
<Main />
33
<NextScript />
34
</body>
35
</html>
36
);
37
}
38
}
39
40
MyDocument.getInitialProps = ctx => {
41
// Resolution order
42
//
43
// On the server:
44
// 1. page.getInitialProps
45
// 2. document.getInitialProps
46
// 3. page.render
47
// 4. document.render
48
//
49
// On the server with error:
50
// 2. document.getInitialProps
51
// 3. page.render
52
// 4. document.render
53
//
54
// On the client
55
// 1. page.getInitialProps
56
// 3. page.render
57
58
// Get the context of the page to collected side effects.
59
const pageContext = getPageContext();
60
const page = ctx.renderPage(Component => props => (
62
registry={pageContext.sheetsRegistry}
63
generateClassName={pageContext.generateClassName}
73
<React.Fragment>
74
<style
75
id="jss-server-side"
76
// eslint-disable-next-line react/no-danger
77
dangerouslySetInnerHTML={{ __html: pageContext.sheetsRegistry.toString() }}
78
/>
79
{flush() || null}
80
</React.Fragment>