-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy path_document.tsx
80 lines (69 loc) · 1.89 KB
/
_document.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import React from 'react';
import Document, { Html, Head, Main, NextScript } from 'next/document';
// Import styled components ServerStyleSheet
import { ServerStyleSheet } from 'styled-components';
interface Props {
styleTags: JSX.Element;
}
export default class MyDocument extends Document<Props> {
static async getInitialProps(ctx) {
const sheet = new ServerStyleSheet();
const originalRenderPage = ctx.renderPage;
try {
ctx.renderPage = () =>
originalRenderPage({
enhanceApp: App => props => sheet.collectStyles(<App {...props} />),
});
const initialProps = await Document.getInitialProps(ctx);
return {
...initialProps,
styles: (
<>
{initialProps.styles}
{sheet.getStyleElement()}
</>
),
};
} finally {
sheet.seal();
}
}
render() {
return (
<Html lang="en">
<Head>
<link
crossOrigin="anonymous"
rel="preload"
href="/static/fonts/Inter-Regular.woff2"
as="font"
/>
<link
crossOrigin="anonymous"
rel="preload"
href="/static/fonts/Inter-Medium.woff2"
as="font"
/>
<link
crossOrigin="anonymous"
rel="preload"
href="/static/fonts/Inter-Bold.woff2"
as="font"
/>
<link rel="preload" href="/static/inter.css" as="style" />
<link rel="stylesheet" type="text/css" href="/static/nprogress.css" />
<link
href="https://fonts.googleapis.com/css?family=&display=swap"
rel="stylesheet"
/>
<link rel="stylesheet" href="/static/inter.css" />
{this.props.styles}
</Head>
<body>
<Main />
<NextScript />
</body>
</Html>
);
}
}