From d50caaeedb593ac0618343b87ec075fca3bd6819 Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Sun, 6 Aug 2023 13:33:14 -0700 Subject: [PATCH 1/2] Fix other case for buildId mismatch --- packages/next/src/server/base-server.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/next/src/server/base-server.ts b/packages/next/src/server/base-server.ts index 354da3ee81aff..75a83709575ab 100644 --- a/packages/next/src/server/base-server.ts +++ b/packages/next/src/server/base-server.ts @@ -743,6 +743,12 @@ export default abstract class Server { // basePath is already stripped by this point if (urlPathname.startsWith(`/_next/data/`)) { parsedUrl.query.__nextDataReq = '1' + + // TODO: remove once normalizeNextData is used instead + if (pathnameInfo.buildId && pathnameInfo.buildId !== this.buildId) { + await this.render404(req, res, parsedUrl) + return + } } const normalizedUrlPath = this.stripNextDataPath(urlPathname) From c0059ed62dfd59f5b047f13de12e4ce948d65800 Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Sun, 6 Aug 2023 15:01:37 -0700 Subject: [PATCH 2/2] Update fix --- packages/next/src/server/base-server.ts | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/packages/next/src/server/base-server.ts b/packages/next/src/server/base-server.ts index 75a83709575ab..33f8887c0d6f6 100644 --- a/packages/next/src/server/base-server.ts +++ b/packages/next/src/server/base-server.ts @@ -743,12 +743,6 @@ export default abstract class Server { // basePath is already stripped by this point if (urlPathname.startsWith(`/_next/data/`)) { parsedUrl.query.__nextDataReq = '1' - - // TODO: remove once normalizeNextData is used instead - if (pathnameInfo.buildId && pathnameInfo.buildId !== this.buildId) { - await this.render404(req, res, parsedUrl) - return - } } const normalizedUrlPath = this.stripNextDataPath(urlPathname) @@ -932,6 +926,16 @@ export default abstract class Server { } parsedUrl.pathname = matchedPath url.pathname = parsedUrl.pathname + + const normalizeResult = await this.normalizeNextData( + req, + res, + parsedUrl + ) + + if (normalizeResult.finished) { + return + } } catch (err) { if (err instanceof DecodeError || err instanceof NormalizeError) { res.statusCode = 400