Skip to content

Commit

Permalink
Merge branch 'canary' into unflag/notFound
Browse files Browse the repository at this point in the history
  • Loading branch information
Timer committed Oct 27, 2020
2 parents a7b7396 + 4026d9b commit 129ff41
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 19 deletions.
30 changes: 16 additions & 14 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 !== '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 @@ -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))
Expand All @@ -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
}
}
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 }
| { 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 }
| { 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

0 comments on commit 129ff41

Please sign in to comment.