Skip to content

Commit

Permalink
Disallow iSSG revalidation period of zero (vercel#9280)
Browse files Browse the repository at this point in the history
* Disallow iSSG revalidation period of zero

* Fix revalidation period in test
  • Loading branch information
Timer authored Nov 1, 2019
1 parent 7c80feb commit aef927d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
15 changes: 8 additions & 7 deletions packages/next/next-server/server/render.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(', ')}.
`
)
}
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/integration/prerender/pages/another/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export async function unstable_getStaticProps () {
world: 'world',
time: new Date().getTime()
},
revalidate: 0
revalidate: 1
}
}

Expand Down
2 changes: 1 addition & 1 deletion test/integration/prerender/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ const expectedManifestRoutes = () => ({
},
'/another': {
dataRoute: `/_next/data/${buildId}/another.json`,
initialRevalidateSeconds: 0,
initialRevalidateSeconds: 1,
srcRoute: null
},
'/blog': {
Expand Down

0 comments on commit aef927d

Please sign in to comment.