From aef927d57661dffe4ae4baf4aaf7189324243d14 Mon Sep 17 00:00:00 2001 From: Joe Haddad Date: Fri, 1 Nov 2019 15:38:02 -0400 Subject: [PATCH] Disallow iSSG revalidation period of zero (#9280) * Disallow iSSG revalidation period of zero * Fix revalidation period in test --- packages/next/next-server/server/render.tsx | 15 ++++++++------- test/integration/prerender/pages/another/index.js | 2 +- test/integration/prerender/test/index.test.js | 2 +- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/packages/next/next-server/server/render.tsx b/packages/next/next-server/server/render.tsx index 1ccf5ec3cf..485ee6c5f0 100644 --- a/packages/next/next-server/server/render.tsx +++ b/packages/next/next-server/server/render.tsx @@ -427,9 +427,9 @@ export async function renderToHTML( if (invalidKeys.length) { throw new Error( - `Additional keys were returned from \`getStaticProps\`. Properties intended for your component must be nested under the \`props\` key, e.g.:\n\n\treturn { props: { title: 'My Title', content: '...' }\n\nKeys that need moved: ${invalidKeys.join( - ', ' - )}. + `Additional keys were returned from \`getStaticProps\`. Properties intended for your component must be nested under the \`props\` key, e.g.:` + + `\n\n\treturn { props: { title: 'My Title', content: '...' }` + + `\n\nKeys that need moved: ${invalidKeys.join(', ')}. ` ) } @@ -442,12 +442,13 @@ export async function renderToHTML( }', cannot be used.` + `\nTry changing the value to '${Math.ceil( data.revalidate - )}' or using \`Math.round()\` if you're computing the value.` + )}' or using \`Math.ceil()\` if you're computing the value.` ) - } else if (data.revalidate < 0) { + } else if (data.revalidate <= 0) { throw new Error( - `A page's revalidate option can not be less than zero. A revalidate option of zero means to revalidate _after_ every request.` + - `\nTo never revalidate, you can set revalidate to \`false\` (only ran once at build-time).` + `A page's revalidate option can not be less than or equal to zero. A revalidate option of zero means to revalidate after _every_ request, and implies stale data cannot be tolerated.` + + `\n\nTo never revalidate, you can set revalidate to \`false\` (only ran once at build-time).` + + `\nTo revalidate as soon as possible, you can set the value to \`1\`.` ) } else if (data.revalidate > 31536000) { // if it's greater than a year for some reason error diff --git a/test/integration/prerender/pages/another/index.js b/test/integration/prerender/pages/another/index.js index d579cba024..06a7b613e7 100644 --- a/test/integration/prerender/pages/another/index.js +++ b/test/integration/prerender/pages/another/index.js @@ -7,7 +7,7 @@ export async function unstable_getStaticProps () { world: 'world', time: new Date().getTime() }, - revalidate: 0 + revalidate: 1 } } diff --git a/test/integration/prerender/test/index.test.js b/test/integration/prerender/test/index.test.js index 8ef7a353c2..d97f1f6f34 100644 --- a/test/integration/prerender/test/index.test.js +++ b/test/integration/prerender/test/index.test.js @@ -83,7 +83,7 @@ const expectedManifestRoutes = () => ({ }, '/another': { dataRoute: `/_next/data/${buildId}/another.json`, - initialRevalidateSeconds: 0, + initialRevalidateSeconds: 1, srcRoute: null }, '/blog': { -- GitLab