Skip to content

overwrite redirect SSG meta.status to 200 for RSC requests #80379

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

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/next/src/server/base-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3067,6 +3067,7 @@ export default abstract class Server<
},
{
routeKind: RouteKind.PAGES,
isRscRequest: isRSCRequest,
incrementalCache,
isRoutePPREnabled,
isFallback: true,
Expand Down Expand Up @@ -3101,6 +3102,7 @@ export default abstract class Server<
}),
{
routeKind: RouteKind.APP_PAGE,
isRscRequest: isRSCRequest,
incrementalCache,
isRoutePPREnabled,
isFallback: true,
Expand Down Expand Up @@ -3173,6 +3175,7 @@ export default abstract class Server<
// rendered and thus check isAppPath.
routeModule?.definition.kind ??
(isAppPath ? RouteKind.APP_PAGE : RouteKind.PAGES),
isRscRequest: isRSCRequest,
incrementalCache,
isOnDemandRevalidate,
isPrefetch: req.headers.purpose === 'prefetch',
Expand Down
1 change: 1 addition & 0 deletions packages/next/src/server/next-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1047,6 +1047,7 @@ export default class NextNodeServer extends BaseServer<
},
{
routeKind: RouteKind.IMAGE,
isRscRequest: false,
incrementalCache: imageOptimizerCache,
isFallback: false,
}
Expand Down
5 changes: 4 additions & 1 deletion packages/next/src/server/response-cache/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export default class ResponseCache implements ResponseCacheBase {
responseGenerator: ResponseGenerator,
context: {
routeKind: RouteKind
isRscRequest: boolean
isOnDemandRevalidate?: boolean
isPrefetch?: boolean
incrementalCache: IncrementalResponseCache
Expand Down Expand Up @@ -198,6 +199,8 @@ export default class ResponseCache implements ResponseCacheBase {
}
)

return toResponseCacheEntry(response)
return toResponseCacheEntry(response, {
isRscRequest: context.isRscRequest,
})
}
}
1 change: 1 addition & 0 deletions packages/next/src/server/response-cache/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export interface ResponseCacheBase {
* provided it will test the filesystem to check.
*/
routeKind: RouteKind
isRscRequest: boolean

/**
* True if this is a fallback request.
Expand Down
13 changes: 11 additions & 2 deletions packages/next/src/server/response-cache/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {

import RenderResult from '../render-result'
import { RouteKind } from '../route-kind'
import { RedirectStatusCode } from '../../client/components/redirect-status-code'

export async function fromResponseCacheEntry(
cacheEntry: ResponseCacheEntry
Expand Down Expand Up @@ -39,7 +40,8 @@ export async function fromResponseCacheEntry(
}

export async function toResponseCacheEntry(
response: IncrementalResponseCacheEntry | null
response: IncrementalResponseCacheEntry | null,
{ isRscRequest }: { isRscRequest: boolean }
): Promise<ResponseCacheEntry | null> {
if (!response) return null

Expand All @@ -62,7 +64,14 @@ export async function toResponseCacheEntry(
html: RenderResult.fromStatic(response.value.html),
rscData: response.value.rscData,
headers: response.value.headers,
status: response.value.status,
status:
// RSC redirect is embedded in the payload itself and handled by client router directly
// This makes it consistent with how it's handled in minimalMode
isRscRequest &&
response.value.status &&
RedirectStatusCode[response.value.status]
? 200
: response.value.status,
postponed: response.value.postponed,
segmentData: response.value.segmentData,
} satisfies CachedAppPageValue)
Expand Down
Loading