diff --git a/packages/next/next-server/server/render.tsx b/packages/next/next-server/server/render.tsx index 9b0ee42be211261..e19e76f39fe220a 100644 --- a/packages/next/next-server/server/render.tsx +++ b/packages/next/next-server/server/render.tsx @@ -624,7 +624,7 @@ export async function renderToHTML( (key) => key !== 'revalidate' && key !== 'props' && - key !== 'unstable_redirect' && + key !== 'redirect' && key !== 'notFound' ) @@ -649,11 +649,11 @@ export async function renderToHTML( } if ( - 'unstable_redirect' in data && - data.unstable_redirect && - typeof data.unstable_redirect === 'object' + 'redirect' in data && + data.redirect && + typeof data.redirect === 'object' ) { - checkRedirectValues(data.unstable_redirect, req) + checkRedirectValues(data.redirect, req) if (isBuildTimeSSG) { throw new Error( @@ -664,10 +664,10 @@ export async function renderToHTML( if (isDataReq) { ;(data as any).props = { - __N_REDIRECT: data.unstable_redirect.destination, + __N_REDIRECT: data.redirect.destination, } } else { - handleRedirect(res, data.unstable_redirect) + handleRedirect(res, data.redirect) return null } } @@ -768,6 +768,11 @@ export async function renderToHTML( `unstable_notFound has been renamed to notFound, please update the field to continue. Page: ${pathname}` ) } + if ((data as any).unstable_redirect) { + throw new Error( + `unstable_redirect has been renamed to redirect, please update the field to continue. Page: ${pathname}` + ) + } if (invalidKeys.length) { throw new Error(invalidKeysMsg('getServerSideProps', invalidKeys)) @@ -784,18 +789,15 @@ export async function renderToHTML( return null } - if ( - 'unstable_redirect' in data && - typeof data.unstable_redirect === 'object' - ) { - checkRedirectValues(data.unstable_redirect, req) + if ('redirect' in data && typeof data.redirect === 'object') { + checkRedirectValues(data.redirect, req) if (isDataReq) { ;(data as any).props = { - __N_REDIRECT: data.unstable_redirect.destination, + __N_REDIRECT: data.redirect.destination, } } else { - handleRedirect(res, data.unstable_redirect) + handleRedirect(res, data.redirect) return null } } diff --git a/packages/next/types/index.d.ts b/packages/next/types/index.d.ts index 3eeae2e87c69cf1..025a778eba96b95 100644 --- a/packages/next/types/index.d.ts +++ b/packages/next/types/index.d.ts @@ -87,7 +87,7 @@ export type GetStaticPropsContext = { export type GetStaticPropsResult

= | { props: P; revalidate?: number | boolean } - | { unstable_redirect: Redirect; revalidate?: number | boolean } + | { redirect: Redirect; revalidate?: number | boolean } | { notFound: true } export type GetStaticProps< @@ -132,7 +132,7 @@ export type GetServerSidePropsContext< export type GetServerSidePropsResult

= | { props: P } - | { unstable_redirect: Redirect } + | { redirect: Redirect } | { notFound: true } export type GetServerSideProps< diff --git a/test/integration/gssp-redirect/pages/gsp-blog/[post].js b/test/integration/gssp-redirect/pages/gsp-blog/[post].js index 18166abd0b48ec5..cd3fae7419a732c 100644 --- a/test/integration/gssp-redirect/pages/gsp-blog/[post].js +++ b/test/integration/gssp-redirect/pages/gsp-blog/[post].js @@ -26,7 +26,7 @@ export const getStaticProps = ({ params }) => { } return { - unstable_redirect: { + redirect: { destination, permanent: params.post.includes('permanent'), }, diff --git a/test/integration/gssp-redirect/pages/gssp-blog/[post].js b/test/integration/gssp-redirect/pages/gssp-blog/[post].js index 4c6af348a5564ba..d01d19f31ae49ab 100644 --- a/test/integration/gssp-redirect/pages/gssp-blog/[post].js +++ b/test/integration/gssp-redirect/pages/gssp-blog/[post].js @@ -16,7 +16,7 @@ export const getServerSideProps = ({ params }) => { } return { - unstable_redirect: { + redirect: { destination, permanent: params.post.includes('permanent'), }, diff --git a/test/integration/gssp-redirect/test/index.test.js b/test/integration/gssp-redirect/test/index.test.js index 5121bdc0f85d67d..4852aac6ad91d0e 100644 --- a/test/integration/gssp-redirect/test/index.test.js +++ b/test/integration/gssp-redirect/test/index.test.js @@ -320,7 +320,7 @@ describe('GS(S)P Redirect Support', () => { export const getStaticProps = ({ params }) => { return { - unstable_redirect: { + redirect: { permanent: true, destination: '/another' }