From 9a10461150f2cfdee83c0d427803f73c70541aba Mon Sep 17 00:00:00 2001 From: Tim Neutkens Date: Fri, 9 Feb 2018 16:55:45 +0100 Subject: [PATCH] =?UTF-8?q?Don=E2=80=99t=20include=20script=20that=20we=20?= =?UTF-8?q?know=20is=20going=20to=20error=20(#3747)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Don’t include script that we know is going to error * Add check to make sure page script is not included * Loop over script tags, cheerio fails on / --- server/document.js | 17 +++++++++++++---- server/render.js | 3 ++- test/integration/basic/test/rendering.js | 10 ++++++++++ 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/server/document.js b/server/document.js index 49eea8a5..6a27ffb2 100644 --- a/server/document.js +++ b/server/document.js @@ -84,12 +84,12 @@ export class Head extends Component { render () { const { head, styles, __NEXT_DATA__ } = this.context._documentProps - const { pathname, buildId, assetPrefix } = __NEXT_DATA__ + const { page, pathname, buildId, assetPrefix } = __NEXT_DATA__ const pagePathname = getPagePathname(pathname) return {(head || []).map((h, i) => React.cloneElement(h, { key: h.key || i }))} - + {page !== '_error' && } {this.getPreloadDynamicChunks()} {this.getPreloadMainLinks()} @@ -173,7 +173,7 @@ export class NextScript extends Component { render () { const { staticMarkup, __NEXT_DATA__, chunks } = this.context._documentProps - const { pathname, buildId, assetPrefix } = __NEXT_DATA__ + const { page, pathname, buildId, assetPrefix } = __NEXT_DATA__ const pagePathname = getPagePathname(pathname) __NEXT_DATA__.chunks = chunks.names @@ -193,9 +193,18 @@ export class NextScript extends Component { __NEXT_REGISTER_CHUNK = function (chunkName, fn) { __NEXT_LOADED_CHUNKS__.push({ chunkName: chunkName, fn: fn }) } + + ${page === '_error' && ` + __NEXT_REGISTER_PAGE('/index', function() { + var error = new Error('Page does not exist: ${htmlescape(pathname)}') + error.statusCode = 404 + + return { error: error } + }) + `} ` }} />} -