| |
| |
| |
| |
| @@ -24,7 +24,8 @@ export function getRedirectError( |
| * [Server Actions](https://nextjs.org/docs/app/building-your-application/data-fetching/server-actions-and-mutations). |
| * |
| * - In a Server Component, this will insert a meta tag to redirect the user to the target page. |
| - * - In a Route Handler or Server Action, it will serve a 307/303 to the caller. |
| + * - In a Route Handler, it will serve a 307 to the caller. |
| + * - In a Server Action, it will perform a client-side navigation when JavaScript is available or serve a 303 for a progressive enhancement form submission. |
| * - In a Server Action, type defaults to 'push' and 'replace' elsewhere. |
| * |
| * Read more: [Next.js Docs: `redirect`](https://nextjs.org/docs/app/api-reference/functions/redirect) |
| @@ -46,7 +47,8 @@ export function redirect( |
| * [Server Actions](https://nextjs.org/docs/app/building-your-application/data-fetching/server-actions-and-mutations). |
| * |
| * - In a Server Component, this will insert a meta tag to redirect the user to the target page. |
| - * - In a Route Handler or Server Action, it will serve a 308/303 to the caller. |
| + * - In a Route Handler, it will serve a 308 to the caller. |
| + * - In a Server Action, it will perform a client-side navigation when JavaScript is available or serve a 303 for a progressive enhancement form submission. |
| * |
| * Read more: [Next.js Docs: `redirect`](https://nextjs.org/docs/app/api-reference/functions/redirect) |
| */ |
| |
| |
| |
| |
| @@ -1272,12 +1272,13 @@ export async function handleAction({ |
| const redirectUrl = getURLFromRedirectError(err) |
| const redirectType = getRedirectTypeFromError(err) |
| |
| - // if it's a fetch action, we'll set the status code for logging/debugging purposes |
| - // but we won't set a Location header, as the redirect will be handled by the client router |
| - res.statusCode = RedirectStatusCode.SeeOther |
| - metadata.statusCode = RedirectStatusCode.SeeOther |
| - |
| if (isFetchAction) { |
| + // Fetch actions communicate redirects through `x-action-redirect` and |
| + // can include the redirect target's Flight response in the body. Since |
| + // this is not an HTTP redirect, keep the response successful. |
| + res.statusCode = 200 |
| + metadata.statusCode = 200 |
| + |
| return { |
| type: 'done', |
| result: await createRedirectRenderResult( |
| @@ -1294,6 +1295,8 @@ export async function handleAction({ |
| } |
| |
| // For an MPA action, the redirect doesn't need a body, just a Location header. |
| + res.statusCode = RedirectStatusCode.SeeOther |
| + metadata.statusCode = RedirectStatusCode.SeeOther |
| res.setHeader('Location', redirectUrl) |
| return { |
| type: 'done', |
| |
| |
| |
| |
| @@ -378,7 +378,8 @@ declare module 'next/navigation' { |
| * [Server Actions](https://nextjs.org/docs/app/building-your-application/data-fetching/server-actions-and-mutations). |
| * |
| * - In a Server Component, this will insert a meta tag to redirect the user to the target page. |
| - * - In a Route Handler or Server Action, it will serve a 307/303 to the caller. |
| + * - In a Route Handler, it will serve a 307 to the caller. |
| + * - In a Server Action, it will perform a client-side navigation when JavaScript is available or serve a 303 for a progressive enhancement form submission. |
| * - In a Server Action, type defaults to 'push' and 'replace' elsewhere. |
| * |
| * Read more: [Next.js Docs: redirect](https://nextjs.org/docs/app/api-reference/functions/redirect) |
| @@ -396,7 +397,8 @@ declare module 'next/navigation' { |
| * [Server Actions](https://nextjs.org/docs/app/building-your-application/data-fetching/server-actions-and-mutations). |
| * |
| * - In a Server Component, this will insert a meta tag to redirect the user to the target page. |
| - * - In a Route Handler or Server Action, it will serve a 308/303 to the caller. |
| + * - In a Route Handler, it will serve a 308 to the caller. |
| + * - In a Server Action, it will perform a client-side navigation when JavaScript is available or serve a 303 for a progressive enhancement form submission. |
| * |
| * Read more: [Next.js Docs: redirect](https://nextjs.org/docs/app/api-reference/functions/redirect) |
| */ |
|
|