From 7ed7f125e07ef0517a331009ed7e32691ba403d3 Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Wed, 11 Sep 2024 14:47:26 -0700 Subject: [PATCH] Remove invalid fallback revalidate value (#69990) This removes our invalid revalidate default fallback when a revalidate value isn't returned from render as render should always return a valid value. We also already have an invariant when an invalid revalidate value is returned we just need to ensure that case could be hit properly. This also fixes some invalid test cases which were sending invalid headers. x-ref: [slack thread](https://vercel.slack.com/archives/C0676QZBWKS/p1726061828198529?thread_ts=1720714625.621179&cid=C0676QZBWKS) --- packages/next/src/server/base-server.ts | 5 +---- packages/next/src/server/render.tsx | 1 + .../required-server-files-i18n.test.ts | 16 ++++++++++------ .../required-server-files.test.ts | 16 ++++++++++------ 4 files changed, 22 insertions(+), 16 deletions(-) diff --git a/packages/next/src/server/base-server.ts b/packages/next/src/server/base-server.ts index 8aed8efebec90..b39edf583d07e 100644 --- a/packages/next/src/server/base-server.ts +++ b/packages/next/src/server/base-server.ts @@ -2573,10 +2573,7 @@ export default abstract class Server { return { ...result, - revalidate: - result.revalidate !== undefined - ? result.revalidate - : /* default to minimum revalidate (this should be an invariant) */ 1, + revalidate: result.revalidate, } }, { diff --git a/packages/next/src/server/render.tsx b/packages/next/src/server/render.tsx index 9038d434ebcdc..2cc3e37ff2d9f 100644 --- a/packages/next/src/server/render.tsx +++ b/packages/next/src/server/render.tsx @@ -1089,6 +1089,7 @@ export async function renderToHTMLImpl( }) ) canAccessRes = false + metadata.revalidate = 0 } catch (serverSidePropsError: any) { // remove not found error code to prevent triggering legacy // 404 rendering diff --git a/test/production/standalone-mode/required-server-files/required-server-files-i18n.test.ts b/test/production/standalone-mode/required-server-files/required-server-files-i18n.test.ts index 820d81b6ffb95..b99348c689905 100644 --- a/test/production/standalone-mode/required-server-files/required-server-files-i18n.test.ts +++ b/test/production/standalone-mode/required-server-files/required-server-files-i18n.test.ts @@ -345,12 +345,16 @@ describe('required server files i18n', () => { expect(isNaN(data2.random)).toBe(false) expect(data2.random).not.toBe(data.random) - const html3 = await renderViaHTTP(appPort, '/some-other-path', undefined, { - headers: { - 'x-matched-path': '/dynamic/[slug]?slug=%5Bslug%5D.json', - 'x-now-route-matches': '1=second&nxtPslug=second', - }, - }) + const html3 = await renderViaHTTP( + appPort, + '/some-other-path?nxtPslug=second', + undefined, + { + headers: { + 'x-matched-path': '/dynamic/[slug]?slug=%5Bslug%5D.json', + }, + } + ) const $3 = cheerio.load(html3) const data3 = JSON.parse($3('#props').text()) diff --git a/test/production/standalone-mode/required-server-files/required-server-files.test.ts b/test/production/standalone-mode/required-server-files/required-server-files.test.ts index d595ff289569d..2d8c58fdee412 100644 --- a/test/production/standalone-mode/required-server-files/required-server-files.test.ts +++ b/test/production/standalone-mode/required-server-files/required-server-files.test.ts @@ -622,12 +622,16 @@ describe('required server files', () => { expect(isNaN(data2.random)).toBe(false) expect(data2.random).not.toBe(data.random) - const html3 = await renderViaHTTP(appPort, '/some-other-path', undefined, { - headers: { - 'x-matched-path': '/dynamic/[slug]', - 'x-now-route-matches': '1=second&nxtPslug=second', - }, - }) + const html3 = await renderViaHTTP( + appPort, + '/some-other-path?nxtPslug=second', + undefined, + { + headers: { + 'x-matched-path': '/dynamic/[slug]', + }, + } + ) const $3 = cheerio.load(html3) const data3 = JSON.parse($3('#props').text())