Skip to content

Commit 129ff41

Browse files
committed
Merge branch 'canary' into unflag/notFound
2 parents a7b7396 + 4026d9b commit 129ff41

File tree

5 files changed

+21
-19
lines changed

5 files changed

+21
-19
lines changed

packages/next/next-server/server/render.tsx

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ export async function renderToHTML(
624624
(key) =>
625625
key !== 'revalidate' &&
626626
key !== 'props' &&
627-
key !== 'unstable_redirect' &&
627+
key !== 'redirect' &&
628628
key !== 'notFound'
629629
)
630630

@@ -649,11 +649,11 @@ export async function renderToHTML(
649649
}
650650

651651
if (
652-
'unstable_redirect' in data &&
653-
data.unstable_redirect &&
654-
typeof data.unstable_redirect === 'object'
652+
'redirect' in data &&
653+
data.redirect &&
654+
typeof data.redirect === 'object'
655655
) {
656-
checkRedirectValues(data.unstable_redirect, req)
656+
checkRedirectValues(data.redirect, req)
657657

658658
if (isBuildTimeSSG) {
659659
throw new Error(
@@ -664,10 +664,10 @@ export async function renderToHTML(
664664

665665
if (isDataReq) {
666666
;(data as any).props = {
667-
__N_REDIRECT: data.unstable_redirect.destination,
667+
__N_REDIRECT: data.redirect.destination,
668668
}
669669
} else {
670-
handleRedirect(res, data.unstable_redirect)
670+
handleRedirect(res, data.redirect)
671671
return null
672672
}
673673
}
@@ -768,6 +768,11 @@ export async function renderToHTML(
768768
`unstable_notFound has been renamed to notFound, please update the field to continue. Page: ${pathname}`
769769
)
770770
}
771+
if ((data as any).unstable_redirect) {
772+
throw new Error(
773+
`unstable_redirect has been renamed to redirect, please update the field to continue. Page: ${pathname}`
774+
)
775+
}
771776

772777
if (invalidKeys.length) {
773778
throw new Error(invalidKeysMsg('getServerSideProps', invalidKeys))
@@ -784,18 +789,15 @@ export async function renderToHTML(
784789
return null
785790
}
786791

787-
if (
788-
'unstable_redirect' in data &&
789-
typeof data.unstable_redirect === 'object'
790-
) {
791-
checkRedirectValues(data.unstable_redirect, req)
792+
if ('redirect' in data && typeof data.redirect === 'object') {
793+
checkRedirectValues(data.redirect, req)
792794

793795
if (isDataReq) {
794796
;(data as any).props = {
795-
__N_REDIRECT: data.unstable_redirect.destination,
797+
__N_REDIRECT: data.redirect.destination,
796798
}
797799
} else {
798-
handleRedirect(res, data.unstable_redirect)
800+
handleRedirect(res, data.redirect)
799801
return null
800802
}
801803
}

packages/next/types/index.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export type GetStaticPropsContext<Q extends ParsedUrlQuery = ParsedUrlQuery> = {
8787

8888
export type GetStaticPropsResult<P> =
8989
| { props: P; revalidate?: number | boolean }
90-
| { unstable_redirect: Redirect; revalidate?: number | boolean }
90+
| { redirect: Redirect; revalidate?: number | boolean }
9191
| { notFound: true }
9292

9393
export type GetStaticProps<
@@ -132,7 +132,7 @@ export type GetServerSidePropsContext<
132132

133133
export type GetServerSidePropsResult<P> =
134134
| { props: P }
135-
| { unstable_redirect: Redirect }
135+
| { redirect: Redirect }
136136
| { notFound: true }
137137

138138
export type GetServerSideProps<

test/integration/gssp-redirect/pages/gsp-blog/[post].js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export const getStaticProps = ({ params }) => {
2626
}
2727

2828
return {
29-
unstable_redirect: {
29+
redirect: {
3030
destination,
3131
permanent: params.post.includes('permanent'),
3232
},

test/integration/gssp-redirect/pages/gssp-blog/[post].js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export const getServerSideProps = ({ params }) => {
1616
}
1717

1818
return {
19-
unstable_redirect: {
19+
redirect: {
2020
destination,
2121
permanent: params.post.includes('permanent'),
2222
},

test/integration/gssp-redirect/test/index.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ describe('GS(S)P Redirect Support', () => {
320320
321321
export const getStaticProps = ({ params }) => {
322322
return {
323-
unstable_redirect: {
323+
redirect: {
324324
permanent: true,
325325
destination: '/another'
326326
}

0 commit comments

Comments
 (0)