-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy path_document.jsx
More file actions
60 lines (52 loc) · 1.77 KB
/
Copy path_document.jsx
File metadata and controls
60 lines (52 loc) · 1.77 KB
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
/*
* Copyright 2025 New Relic Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/
// 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