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