Unverified Commit 4026d9be authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Remove unstable_ prefix from unstable_redirect (#18282)

parent 1b22a39e
...@@ -624,7 +624,7 @@ export async function renderToHTML( ...@@ -624,7 +624,7 @@ export async function renderToHTML(
(key) => (key) =>
key !== 'revalidate' && key !== 'revalidate' &&
key !== 'props' && key !== 'props' &&
key !== 'unstable_redirect' && key !== 'redirect' &&
key !== 'unstable_notFound' key !== 'unstable_notFound'
) )
...@@ -649,11 +649,11 @@ export async function renderToHTML( ...@@ -649,11 +649,11 @@ export async function renderToHTML(
} }
if ( if (
'unstable_redirect' in data && 'redirect' in data &&
data.unstable_redirect && data.redirect &&
typeof data.unstable_redirect === 'object' typeof data.redirect === 'object'
) { ) {
checkRedirectValues(data.unstable_redirect, req) checkRedirectValues(data.redirect, req)
if (isBuildTimeSSG) { if (isBuildTimeSSG) {
throw new Error( throw new Error(
...@@ -664,10 +664,10 @@ export async function renderToHTML( ...@@ -664,10 +664,10 @@ export async function renderToHTML(
if (isDataReq) { if (isDataReq) {
;(data as any).props = { ;(data as any).props = {
__N_REDIRECT: data.unstable_redirect.destination, __N_REDIRECT: data.redirect.destination,
} }
} else { } else {
handleRedirect(res, data.unstable_redirect) handleRedirect(res, data.redirect)
return null return null
} }
} }
...@@ -760,11 +760,15 @@ export async function renderToHTML( ...@@ -760,11 +760,15 @@ export async function renderToHTML(
const invalidKeys = Object.keys(data).filter( const invalidKeys = Object.keys(data).filter(
(key) => (key) =>
key !== 'props' && key !== 'props' && key !== 'redirect' && key !== 'unstable_notFound'
key !== 'unstable_redirect' &&
key !== 'unstable_notFound'
) )
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) { if (invalidKeys.length) {
throw new Error(invalidKeysMsg('getServerSideProps', invalidKeys)) throw new Error(invalidKeysMsg('getServerSideProps', invalidKeys))
} }
...@@ -780,18 +784,15 @@ export async function renderToHTML( ...@@ -780,18 +784,15 @@ export async function renderToHTML(
return null return null
} }
if ( if ('redirect' in data && typeof data.redirect === 'object') {
'unstable_redirect' in data && checkRedirectValues(data.redirect, req)
typeof data.unstable_redirect === 'object'
) {
checkRedirectValues(data.unstable_redirect, req)
if (isDataReq) { if (isDataReq) {
;(data as any).props = { ;(data as any).props = {
__N_REDIRECT: data.unstable_redirect.destination, __N_REDIRECT: data.redirect.destination,
} }
} else { } else {
handleRedirect(res, data.unstable_redirect) handleRedirect(res, data.redirect)
return null return null
} }
} }
......
...@@ -87,7 +87,7 @@ export type GetStaticPropsContext<Q extends ParsedUrlQuery = ParsedUrlQuery> = { ...@@ -87,7 +87,7 @@ export type GetStaticPropsContext<Q extends ParsedUrlQuery = ParsedUrlQuery> = {
export type GetStaticPropsResult<P> = export type GetStaticPropsResult<P> =
| { props: P; revalidate?: number | boolean } | { props: P; revalidate?: number | boolean }
| { unstable_redirect: Redirect; revalidate?: number | boolean } | { redirect: Redirect; revalidate?: number | boolean }
| { unstable_notFound: true } | { unstable_notFound: true }
export type GetStaticProps< export type GetStaticProps<
...@@ -132,7 +132,7 @@ export type GetServerSidePropsContext< ...@@ -132,7 +132,7 @@ export type GetServerSidePropsContext<
export type GetServerSidePropsResult<P> = export type GetServerSidePropsResult<P> =
| { props: P } | { props: P }
| { unstable_redirect: Redirect } | { redirect: Redirect }
| { unstable_notFound: true } | { unstable_notFound: true }
export type GetServerSideProps< export type GetServerSideProps<
......
...@@ -26,7 +26,7 @@ export const getStaticProps = ({ params }) => { ...@@ -26,7 +26,7 @@ export const getStaticProps = ({ params }) => {
} }
return { return {
unstable_redirect: { redirect: {
destination, destination,
permanent: params.post.includes('permanent'), permanent: params.post.includes('permanent'),
}, },
......
...@@ -16,7 +16,7 @@ export const getServerSideProps = ({ params }) => { ...@@ -16,7 +16,7 @@ export const getServerSideProps = ({ params }) => {
} }
return { return {
unstable_redirect: { redirect: {
destination, destination,
permanent: params.post.includes('permanent'), permanent: params.post.includes('permanent'),
}, },
......
...@@ -320,7 +320,7 @@ describe('GS(S)P Redirect Support', () => { ...@@ -320,7 +320,7 @@ describe('GS(S)P Redirect Support', () => {
export const getStaticProps = ({ params }) => { export const getStaticProps = ({ params }) => {
return { return {
unstable_redirect: { redirect: {
permanent: true, permanent: true,
destination: '/another' destination: '/another'
} }
......
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