-
Notifications
You must be signed in to change notification settings - Fork 28.3k
/
Copy pathdocument.js
62 lines (51 loc) · 1.57 KB
/
document.js
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
import React, { Component, PropTypes } from 'react'
import htmlescape from 'htmlescape'
export default class Document extends Component {
static childContextTypes = {
_documentProps: PropTypes.any
}
getChildContext () {
return {
_documentProps: this.props
}
}
render () {
return <html>
<Head/>
<body>
<Main/>
<DevTools/>
<NextScript/>
</body>
</html>
}
}
export function Head (props, context) {
const { head, css } = context._documentProps
const h = (head || [])
.map((h, i) => React.cloneElement(h, { key: '_next' + i }))
return <head>
{h}
<style data-aphrodite>{css.content}</style>
</head>
}
Head.contextTypes = { _documentProps: PropTypes.any }
export function Main (props, context) {
const { html, data } = context._documentProps;
return <div>
<div id='__next' dangerouslySetInnerHTML={{ __html: html }} />
<script dangerouslySetInnerHTML={{ __html: '__NEXT_DATA__ = ' + htmlescape(data) }}></script>
</div>
}
Main.contextTypes = { _documentProps: PropTypes.any }
export function DevTools (props, context) {
const { hotReload } = context._documentProps
return hotReload ? <div id='__next-hot-code-reloading-indicator'/> : null
}
DevTools.contextTypes = { _documentProps: PropTypes.any }
export function NextScript (props, context) {
const { hotReload } = context._documentProps;
const src = !hotReload ? '/_next/next.bundle.js' : '/_next/next-dev.bundle.js'
return <script type='text/javascript' src={src}/>
}
NextScript.contextTypes = { _documentProps: PropTypes.any }