Unverified Commit 97a6b64f authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Rename unstable GSP field (#11602)

* Rename unstable GSP revalidate field

* Update error message

* Tweak error message some more

* Apply suggestions from code review
Co-Authored-By: 's avatarJoe Haddad <joe.haddad@zeit.co>
Co-authored-by: 's avatarJoe Haddad <joe.haddad@zeit.co>
parent bf96337c
...@@ -33,3 +33,9 @@ export const SERVER_PROPS_SSG_CONFLICT = `You can not use getStaticProps with ge ...@@ -33,3 +33,9 @@ export const SERVER_PROPS_SSG_CONFLICT = `You can not use getStaticProps with ge
export const PAGES_404_GET_INITIAL_PROPS_ERROR = `\`pages/404\` can not have getInitialProps/getServerSideProps, https://err.sh/next.js/404-get-initial-props` export const PAGES_404_GET_INITIAL_PROPS_ERROR = `\`pages/404\` can not have getInitialProps/getServerSideProps, https://err.sh/next.js/404-get-initial-props`
export const SERVER_PROPS_EXPORT_ERROR = `pages with \`getServerSideProps\` can not be exported. See more info here: https://err.sh/next.js/gss-export` export const SERVER_PROPS_EXPORT_ERROR = `pages with \`getServerSideProps\` can not be exported. See more info here: https://err.sh/next.js/gss-export`
export const UNSTABLE_REVALIDATE_RENAME_ERROR =
'The `revalidate` property is not yet available for general use.\n' +
'To try the experimental implementation, please use `unstable_revalidate` instead.\n' +
"We're excited for you to try this feature—please share all feedback on the RFC:\n" +
'https://nextjs.link/issg'
...@@ -7,6 +7,7 @@ import { ...@@ -7,6 +7,7 @@ import {
SERVER_PROPS_GET_INIT_PROPS_CONFLICT, SERVER_PROPS_GET_INIT_PROPS_CONFLICT,
SERVER_PROPS_SSG_CONFLICT, SERVER_PROPS_SSG_CONFLICT,
SSG_GET_INITIAL_PROPS_CONFLICT, SSG_GET_INITIAL_PROPS_CONFLICT,
UNSTABLE_REVALIDATE_RENAME_ERROR,
} from '../../lib/constants' } from '../../lib/constants'
import { isSerializableProps } from '../../lib/is-serializable-props' import { isSerializableProps } from '../../lib/is-serializable-props'
import { isInAmpMode } from '../lib/amp' import { isInAmpMode } from '../lib/amp'
...@@ -518,9 +519,13 @@ export async function renderToHTML( ...@@ -518,9 +519,13 @@ export async function renderToHTML(
} }
const invalidKeys = Object.keys(data).filter( const invalidKeys = Object.keys(data).filter(
key => key !== 'revalidate' && key !== 'props' key => key !== 'unstable_revalidate' && key !== 'props'
) )
if (invalidKeys.includes('revalidate')) {
throw new Error(UNSTABLE_REVALIDATE_RENAME_ERROR)
}
if (invalidKeys.length) { if (invalidKeys.length) {
throw new Error(invalidKeysMsg('getStaticProps', invalidKeys)) throw new Error(invalidKeysMsg('getStaticProps', invalidKeys))
} }
...@@ -535,41 +540,41 @@ export async function renderToHTML( ...@@ -535,41 +540,41 @@ export async function renderToHTML(
) )
} }
if (typeof data.revalidate === 'number') { if (typeof data.unstable_revalidate === 'number') {
if (!Number.isInteger(data.revalidate)) { if (!Number.isInteger(data.unstable_revalidate)) {
throw new Error( throw new Error(
`A page's revalidate option must be seconds expressed as a natural number. Mixed numbers, such as '${data.revalidate}', cannot be used.` + `A page's revalidate option must be seconds expressed as a natural number. Mixed numbers, such as '${data.unstable_revalidate}', cannot be used.` +
`\nTry changing the value to '${Math.ceil( `\nTry changing the value to '${Math.ceil(
data.revalidate data.unstable_revalidate
)}' or using \`Math.ceil()\` if you're computing the value.` )}' or using \`Math.ceil()\` if you're computing the value.`
) )
} else if (data.revalidate <= 0) { } else if (data.unstable_revalidate <= 0) {
throw new Error( throw new Error(
`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.` + `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).` + `\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\`.` `\nTo revalidate as soon as possible, you can set the value to \`1\`.`
) )
} else if (data.revalidate > 31536000) { } else if (data.unstable_revalidate > 31536000) {
// if it's greater than a year for some reason error // if it's greater than a year for some reason error
console.warn( console.warn(
`Warning: A page's revalidate option was set to more than a year. This may have been done in error.` + `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\`!` `\nTo only run getStaticProps at build-time and not revalidate at runtime, you can set \`revalidate\` to \`false\`!`
) )
} }
} else if (data.revalidate === true) { } else if (data.unstable_revalidate === true) {
// When enabled, revalidate after 1 second. This value is optimal for // When enabled, revalidate after 1 second. This value is optimal for
// the most up-to-date page possible, but without a 1-to-1 // the most up-to-date page possible, but without a 1-to-1
// request-refresh ratio. // request-refresh ratio.
data.revalidate = 1 data.unstable_revalidate = 1
} else { } else {
// By default, we never revalidate. // By default, we never revalidate.
data.revalidate = false data.unstable_revalidate = false
} }
props.pageProps = data.props props.pageProps = data.props
// pass up revalidate and props for export // pass up revalidate and props for export
// TODO: change this to a different passing mechanism // TODO: change this to a different passing mechanism
;(renderOpts as any).revalidate = data.revalidate ;(renderOpts as any).revalidate = data.unstable_revalidate
;(renderOpts as any).pageData = props ;(renderOpts as any).pageData = props
} }
......
...@@ -74,7 +74,7 @@ export type GetStaticProps< ...@@ -74,7 +74,7 @@ export type GetStaticProps<
previewData?: any previewData?: any
}) => Promise<{ }) => Promise<{
props: P props: P
revalidate?: number | boolean unstable_revalidate?: number | boolean
}> }>
export type GetStaticPaths< export type GetStaticPaths<
......
...@@ -30,7 +30,7 @@ export async function getStaticProps() { ...@@ -30,7 +30,7 @@ export async function getStaticProps() {
// Do not pass any sensitive values here as they will // Do not pass any sensitive values here as they will
// be made PUBLICLY available in `pageProps` // be made PUBLICLY available in `pageProps`
props: { env: items }, props: { env: items },
revalidate: 1, unstable_revalidate: 1,
} }
} }
......
...@@ -30,7 +30,7 @@ export async function getStaticProps() { ...@@ -30,7 +30,7 @@ export async function getStaticProps() {
// Do not pass any sensitive values here as they will // Do not pass any sensitive values here as they will
// be made PUBLICLY available in `pageProps` // be made PUBLICLY available in `pageProps`
props: { env: items }, props: { env: items },
revalidate: 1, unstable_revalidate: 1,
} }
} }
......
...@@ -18,7 +18,7 @@ export async function getStaticProps() { ...@@ -18,7 +18,7 @@ export async function getStaticProps() {
world: text, world: text,
time: new Date().getTime(), time: new Date().getTime(),
}, },
revalidate: true, unstable_revalidate: true,
} }
} }
......
...@@ -18,7 +18,7 @@ export async function getStaticProps({ params }) { ...@@ -18,7 +18,7 @@ export async function getStaticProps({ params }) {
comment: params.comment, comment: params.comment,
time: new Date().getTime(), time: new Date().getTime(),
}, },
revalidate: 2, unstable_revalidate: 2,
} }
} }
......
...@@ -42,7 +42,7 @@ export async function getStaticProps({ params }) { ...@@ -42,7 +42,7 @@ export async function getStaticProps({ params }) {
post: params.post, post: params.post,
time: (await import('perf_hooks')).performance.now(), time: (await import('perf_hooks')).performance.now(),
}, },
revalidate: 10, unstable_revalidate: 10,
} }
} }
......
...@@ -7,7 +7,7 @@ export async function getStaticProps() { ...@@ -7,7 +7,7 @@ export async function getStaticProps() {
slugs: ['post-1', 'post-2'], slugs: ['post-1', 'post-2'],
time: (await import('perf_hooks')).performance.now(), time: (await import('perf_hooks')).performance.now(),
}, },
revalidate: 10, unstable_revalidate: 10,
} }
} }
......
...@@ -7,7 +7,7 @@ export async function getStaticProps({ params: { slug } }) { ...@@ -7,7 +7,7 @@ export async function getStaticProps({ params: { slug } }) {
props: { props: {
slug, slug,
}, },
revalidate: 1, unstable_revalidate: 1,
} }
} }
......
...@@ -9,7 +9,7 @@ export async function getStaticProps({ params: { slug } }) { ...@@ -9,7 +9,7 @@ export async function getStaticProps({ params: { slug } }) {
props: { props: {
slug, slug,
}, },
revalidate: 1, unstable_revalidate: 1,
} }
} }
......
...@@ -5,7 +5,7 @@ export async function getStaticProps() { ...@@ -5,7 +5,7 @@ export async function getStaticProps() {
return { return {
props: { world: 'world', time: new Date().getTime() }, props: { world: 'world', time: new Date().getTime() },
// bad-prop // bad-prop
revalidate: 1, unstable_revalidate: 1,
} }
} }
......
...@@ -10,7 +10,7 @@ export async function getStaticProps({ params }) { ...@@ -10,7 +10,7 @@ export async function getStaticProps({ params }) {
time: new Date().getTime(), time: new Date().getTime(),
random: Math.random(), random: Math.random(),
}, },
revalidate: false, unstable_revalidate: false,
} }
} }
......
...@@ -11,7 +11,7 @@ export async function getStaticProps({ params }) { ...@@ -11,7 +11,7 @@ export async function getStaticProps({ params }) {
user: params.user, user: params.user,
time: (await import('perf_hooks')).performance.now(), time: (await import('perf_hooks')).performance.now(),
}, },
revalidate: 10, unstable_revalidate: 10,
} }
} }
......
...@@ -20,7 +20,7 @@ export const getStaticProps: GetStaticProps<Props, Params> = async ({ ...@@ -20,7 +20,7 @@ export const getStaticProps: GetStaticProps<Props, Params> = async ({
}) => { }) => {
return { return {
props: { data: params!.slug }, props: { data: params!.slug },
revalidate: false, unstable_revalidate: false,
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment