-
Notifications
You must be signed in to change notification settings - Fork 3.6k
/
Copy path_document.tsx
68 lines (63 loc) · 2.02 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
/* eslint-disable jsx-a11y/iframe-has-title */
import { FARMS_API } from 'config/constants/endpoints'
import Document, { DocumentContext, Head, Html, Main, NextScript } from 'next/document'
import { ServerStyleSheet } from 'styled-components'
class MyDocument extends Document {
static async getInitialProps(ctx: DocumentContext) {
const sheet = new ServerStyleSheet()
const originalRenderPage = ctx.renderPage
try {
// eslint-disable-next-line no-param-reassign
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 translate="no">
<Head>
{process.env.NEXT_PUBLIC_NODE_PRODUCTION && (
<link rel="preconnect" href={process.env.NEXT_PUBLIC_NODE_PRODUCTION} />
)}
<link rel="preconnect" href="https://fonts.gstatic.com" />
<link rel="preconnect" href={FARMS_API} />
<link
href="https://fonts.googleapis.com/css2?family=Kanit:wght@400;600;800&display=swap"
rel="stylesheet"
/>
<link rel="shortcut icon" href="/favicon.ico" />
<link rel="apple-touch-icon" href="/logo.png" />
<link rel="manifest" href="/manifest.json" />
</Head>
<body>
<noscript>
<iframe
src={`https://www.googletagmanager.com/ns.html?id=${process.env.NEXT_PUBLIC_NEW_GTAG}`}
height="0"
width="0"
style={{ display: 'none', visibility: 'hidden' }}
/>
</noscript>
<Main />
<NextScript />
<div id="portal-root" />
</body>
</Html>
)
}
}
export default MyDocument