-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy path_document.jsx
55 lines (48 loc) · 1.66 KB
/
_document.jsx
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
// This file provides the overall layout of the site via the `render` method.
import Document, { Html, Head, Main, NextScript } from 'next/document'
import newrelic from 'newrelic'
// In order to inject the browser agent we need to perform an asynchronous
// operation. To do that, we need to extend the `Document` object as
// described in
// https://nextjs.org/docs/pages/building-your-application/routing/custom-document#customizing-renderpage
class RootDocument extends Document {
static async getInitialProps(context) {
const initialProps = await Document.getInitialProps(context)
if (newrelic.agent.collector.isConnected() === false) {
await new Promise((resolve) => {
newrelic.agent.on("connected", resolve)
})
}
const browserTimingHeader = newrelic.getBrowserTimingHeader({
hasToRemoveScriptWrapper: true,
allowTransactionlessInjection: true,
})
return {
...initialProps,
browserTimingHeader,
}
}
render() {
return (
<Html>
<Head>
<script
type="text/javascript"
// The body of the script element comes from the async evaluation
// of `getInitialProps`. We use the special
// `dangerouslySetInnerHTML` to provide that element body. Since
// it requires an object with an `__html` property, we pass in an
// object literal.
dangerouslySetInnerHTML={{ __html: this.props.browserTimingHeader }}
/>
<link rel="stylesheet" href="/style.css" />
</Head>
<body>
<Main />
<NextScript />
</body>
</Html>
)
}
}
export default RootDocument