Unverified Commit b65c464d authored by Tim Neutkens's avatar Tim Neutkens Committed by GitHub

Move __NEXT_DATA__ into an application/json script tag (#5584)

* Move __NEXT_DATA__ into a application/json script tag

As outlined by @dav-is here https://github.com/zeit/next.js/pull/4943

* Set __NEXT_DATA__ for backwards compatability
parent 1aa96522
...@@ -19,18 +19,19 @@ if (!window.Promise) { ...@@ -19,18 +19,19 @@ if (!window.Promise) {
window.Promise = Promise window.Promise = Promise
} }
const data = JSON.parse(document.getElementById('__NEXT_DATA__').textContent)
window.__NEXT_DATA__ = data
const { const {
__NEXT_DATA__: { props,
props, err,
err, page,
page, query,
query, buildId,
buildId, assetPrefix,
assetPrefix, runtimeConfig,
runtimeConfig, dynamicIds
dynamicIds } = data
}
} = window
const prefix = assetPrefix || '' const prefix = assetPrefix || ''
......
...@@ -186,8 +186,7 @@ export class NextScript extends Component { ...@@ -186,8 +186,7 @@ export class NextScript extends Component {
static getInlineScriptSource (documentProps) { static getInlineScriptSource (documentProps) {
const { __NEXT_DATA__ } = documentProps const { __NEXT_DATA__ } = documentProps
const { page } = __NEXT_DATA__ return htmlescape(__NEXT_DATA__)
return `__NEXT_DATA__ = ${htmlescape(__NEXT_DATA__)};`
} }
render () { render () {
...@@ -197,7 +196,7 @@ export class NextScript extends Component { ...@@ -197,7 +196,7 @@ export class NextScript extends Component {
return <Fragment> return <Fragment>
{devFiles ? devFiles.map((file) => <script key={file} src={`${assetPrefix}/_next/${file}`} nonce={this.props.nonce} />) : null} {devFiles ? devFiles.map((file) => <script key={file} src={`${assetPrefix}/_next/${file}`} nonce={this.props.nonce} />) : null}
{staticMarkup ? null : <script nonce={this.props.nonce} dangerouslySetInnerHTML={{ {staticMarkup ? null : <script id="__NEXT_DATA__" type="application/json" nonce={this.props.nonce} dangerouslySetInnerHTML={{
__html: NextScript.getInlineScriptSource(this.context._documentProps) __html: NextScript.getInlineScriptSource(this.context._documentProps)
}} />} }} />}
{page !== '/_error' && <script async id={`__NEXT_PAGE__${page}`} src={`${assetPrefix}/_next/static/${buildId}/pages${pagePathname}`} nonce={this.props.nonce} />} {page !== '/_error' && <script async id={`__NEXT_PAGE__${page}`} src={`${assetPrefix}/_next/static/${buildId}/pages${pagePathname}`} nonce={this.props.nonce} />}
......
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