Skip to content

Commit

Permalink
Configure the Default Revalidate
Browse files Browse the repository at this point in the history
The default revalidate behavior should be configured by Next.js. Otherwise, the behavior might drift or change in non-semver compliant ways between Next.js and the builder (or other 3rd party setups).
  • Loading branch information
Timer committed Sep 27, 2019
1 parent e8522f4 commit 00147f1
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/next/next-server/server/render.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,12 @@ export async function renderToHTML(
`Warning: A page's revalidate option was set to more than a year. This may have been done in error.\nTo only run getStaticProps at build-time and not revalidate at runtime, you can set \`revalidate\` to \`false\`!`
)
}
} else if (data.revalidate === false) {
} else {
// By default, we revalidate after 1 second. This value is optimal for
// the most up-to-date page possible, but without a 1-to-1
// request-refresh ratio.
data.revalidate = 1
}

props.pageProps = data.props
Expand Down
25 changes: 25 additions & 0 deletions test/integration/prerender/pages/default-revalidate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import Link from 'next/link'

// eslint-disable-next-line camelcase
export async function unstable_getStaticProps () {
return {
props: {
world: 'world',
time: new Date().getTime()
}
}
}

export default ({ world, time }) => (
<>
<p>hello {world}</p>
<span>time: {time}</span>
<Link href='/'>
<a id='home'>to home</a>
</Link>
<br />
<Link href='/something'>
<a id='something'>to something</a>
</Link>
</>
)
3 changes: 3 additions & 0 deletions test/integration/prerender/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ const runTests = (dev = false) => {
'/another': {
initialRevalidateSeconds: 0
},
'/default-revalidate': {
initialRevalidateSeconds: 1
},
'/something': {
initialRevalidateSeconds: false
}
Expand Down

0 comments on commit 00147f1

Please sign in to comment.