Skip to content

Commit 4026d9b

Browse files
authored
Remove unstable_ prefix from unstable_redirect (#18282)
1 parent 1b22a39 commit 4026d9b

File tree

5 files changed

+23
-22
lines changed

5 files changed

+23
-22
lines changed

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

Lines changed: 18 additions & 17 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 !== 'unstable_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
}
@@ -760,11 +760,15 @@ export async function renderToHTML(
760760

761761
const invalidKeys = Object.keys(data).filter(
762762
(key) =>
763-
key !== 'props' &&
764-
key !== 'unstable_redirect' &&
765-
key !== 'unstable_notFound'
763+
key !== 'props' && key !== 'redirect' && key !== 'unstable_notFound'
766764
)
767765

766+
if ((data as any).unstable_redirect) {
767+
throw new Error(
768+
`unstable_redirect has been renamed to redirect, please update the field to continue. Page: ${pathname}`
769+
)
770+
}
771+
768772
if (invalidKeys.length) {
769773
throw new Error(invalidKeysMsg('getServerSideProps', invalidKeys))
770774
}
@@ -780,18 +784,15 @@ export async function renderToHTML(
780784
return null
781785
}
782786

783-
if (
784-
'unstable_redirect' in data &&
785-
typeof data.unstable_redirect === 'object'
786-
) {
787-
checkRedirectValues(data.unstable_redirect, req)
787+
if ('redirect' in data && typeof data.redirect === 'object') {
788+
checkRedirectValues(data.redirect, req)
788789

789790
if (isDataReq) {
790791
;(data as any).props = {
791-
__N_REDIRECT: data.unstable_redirect.destination,
792+
__N_REDIRECT: data.redirect.destination,
792793
}
793794
} else {
794-
handleRedirect(res, data.unstable_redirect)
795+
handleRedirect(res, data.redirect)
795796
return null
796797
}
797798
}

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
| { unstable_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
| { unstable_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)