Skip to content

Commit

Permalink
Configure the Default Revalidate (#8880)
Browse files Browse the repository at this point in the history
* Configure the Default Revalidate
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).

* Add additional comment
  • Loading branch information
Timer authored Sep 27, 2019
1 parent 01e5471 commit 2aa1203
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
8 changes: 8 additions & 0 deletions packages/next/next-server/server/render.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,14 @@ export async function renderToHTML(
`\nTo only run getStaticProps at build-time and not revalidate at runtime, you can set \`revalidate\` to \`false\`!`
)
}
} else if (data.revalidate === false) {
// `false` is an allowed behavior. We'll catch `revalidate: true` and
// fall into our default behavior.
} 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 2aa1203

Please sign in to comment.