1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00

Remove extra div (#3327)

* Replace extra div with React fragment.

* Fix linter

* Replace extra div with React fragment.

* Fix linter

* fix script tag, backport nonce attribute
This commit is contained in:
Roman Vanesyan 2017-11-24 02:12:52 +05:00 committed by Tim Neutkens
parent 5ede8c9dc3
commit 7a08e1b5f8

View file

@ -3,6 +3,10 @@ import PropTypes from 'prop-types'
import htmlescape from 'htmlescape'
import flush from 'styled-jsx/server'
function Fragment ({ children }) {
return children
}
export default class Document extends Component {
static getInitialProps ({ renderPage }) {
const { html, head, errorHtml, chunks } = renderPage()
@ -96,22 +100,18 @@ export class Head extends Component {
}
export class Main extends Component {
static propTypes = {
className: PropTypes.string
}
static contextTypes = {
_documentProps: PropTypes.any
}
render () {
const { html, errorHtml } = this.context._documentProps
const { className } = this.props
return (
<div className={className}>
<Fragment>
<div id='__next' dangerouslySetInnerHTML={{ __html: html }} />
<div id='__next-error' dangerouslySetInnerHTML={{ __html: errorHtml }} />
</div>
</Fragment>
)
}
}
@ -159,7 +159,7 @@ export class NextScript extends Component {
const { chunks, __NEXT_DATA__ } = this.context._documentProps
let { assetPrefix, buildId } = __NEXT_DATA__
return (
<div>
<Fragment>
{chunks.map((chunk) => (
<script
async
@ -168,7 +168,7 @@ export class NextScript extends Component {
src={`${assetPrefix}/_next/${buildId}/webpack/chunks/${chunk}`}
/>
))}
</div>
</Fragment>
)
}
@ -179,7 +179,7 @@ export class NextScript extends Component {
__NEXT_DATA__.chunks = chunks
return <div>
return <Fragment>
{staticMarkup ? null : <script nonce={this.props.nonce} dangerouslySetInnerHTML={{
__html: `
__NEXT_DATA__ = ${htmlescape(__NEXT_DATA__)}
@ -200,7 +200,7 @@ export class NextScript extends Component {
<script async id={`__NEXT_PAGE__/_error`} type='text/javascript' src={`${assetPrefix}/_next/${buildId}/page/_error/index.js`} />
{staticMarkup ? null : this.getDynamicChunks()}
{staticMarkup ? null : this.getScripts()}
</div>
</Fragment>
}
}