mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
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
This commit is contained in:
parent
1aa965226e
commit
b65c464d60
|
@ -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 {
|
||||||
|
|
||||||
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 {
|
||||||
|
|
||||||
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} />}
|
||||||
|
|
Loading…
Reference in a new issue