Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unstable_ prefix from unstable_redirect #18282

Merged
merged 4 commits into from Oct 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 18 additions & 17 deletions packages/next/next-server/server/render.tsx
Expand Up @@ -624,7 +624,7 @@ export async function renderToHTML(
(key) =>
key !== 'revalidate' &&
key !== 'props' &&
key !== 'unstable_redirect' &&
key !== 'redirect' &&
key !== 'unstable_notFound'
)

Expand All @@ -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(
Expand All @@ -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
}
}
Expand Down Expand Up @@ -760,11 +760,15 @@ export async function renderToHTML(

const invalidKeys = Object.keys(data).filter(
(key) =>
key !== 'props' &&
key !== 'unstable_redirect' &&
key !== 'unstable_notFound'
key !== 'props' && key !== '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) {
throw new Error(invalidKeysMsg('getServerSideProps', invalidKeys))
}
Expand All @@ -780,18 +784,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
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/next/types/index.d.ts
Expand Up @@ -87,7 +87,7 @@ export type GetStaticPropsContext<Q extends ParsedUrlQuery = ParsedUrlQuery> = {

export type GetStaticPropsResult<P> =
| { props: P; revalidate?: number | boolean }
| { unstable_redirect: Redirect; revalidate?: number | boolean }
| { redirect: Redirect; revalidate?: number | boolean }
| { unstable_notFound: true }

export type GetStaticProps<
Expand Down Expand Up @@ -132,7 +132,7 @@ export type GetServerSidePropsContext<

export type GetServerSidePropsResult<P> =
| { props: P }
| { unstable_redirect: Redirect }
| { redirect: Redirect }
| { unstable_notFound: true }

export type GetServerSideProps<
Expand Down
2 changes: 1 addition & 1 deletion test/integration/gssp-redirect/pages/gsp-blog/[post].js
Expand Up @@ -26,7 +26,7 @@ export const getStaticProps = ({ params }) => {
}

return {
unstable_redirect: {
redirect: {
destination,
permanent: params.post.includes('permanent'),
},
Expand Down
2 changes: 1 addition & 1 deletion test/integration/gssp-redirect/pages/gssp-blog/[post].js
Expand Up @@ -16,7 +16,7 @@ export const getServerSideProps = ({ params }) => {
}

return {
unstable_redirect: {
redirect: {
destination,
permanent: params.post.includes('permanent'),
},
Expand Down
2 changes: 1 addition & 1 deletion test/integration/gssp-redirect/test/index.test.js
Expand Up @@ -320,7 +320,7 @@ describe('GS(S)P Redirect Support', () => {
export const getStaticProps = ({ params }) => {
return {
unstable_redirect: {
redirect: {
permanent: true,
destination: '/another'
}
Expand Down