Commit 7a08e1b5 authored by Roman Vanesyan's avatar Roman Vanesyan Committed by Tim Neutkens

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
parent 5ede8c9d
......@@ -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>
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment