Skip to content

Commit fec157b

Browse files
committed
overwrite redirect SSG meta.status to 200 for RSC requests
1 parent 81d4a8b commit fec157b

File tree

5 files changed

+20
-3
lines changed

5 files changed

+20
-3
lines changed

packages/next/src/server/base-server.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3067,6 +3067,7 @@ export default abstract class Server<
30673067
},
30683068
{
30693069
routeKind: RouteKind.PAGES,
3070+
isRscRequest: isRSCRequest,
30703071
incrementalCache,
30713072
isRoutePPREnabled,
30723073
isFallback: true,
@@ -3101,6 +3102,7 @@ export default abstract class Server<
31013102
}),
31023103
{
31033104
routeKind: RouteKind.APP_PAGE,
3105+
isRscRequest: isRSCRequest,
31043106
incrementalCache,
31053107
isRoutePPREnabled,
31063108
isFallback: true,
@@ -3173,6 +3175,7 @@ export default abstract class Server<
31733175
// rendered and thus check isAppPath.
31743176
routeModule?.definition.kind ??
31753177
(isAppPath ? RouteKind.APP_PAGE : RouteKind.PAGES),
3178+
isRscRequest: isRSCRequest,
31763179
incrementalCache,
31773180
isOnDemandRevalidate,
31783181
isPrefetch: req.headers.purpose === 'prefetch',

packages/next/src/server/next-server.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,6 +1047,7 @@ export default class NextNodeServer extends BaseServer<
10471047
},
10481048
{
10491049
routeKind: RouteKind.IMAGE,
1050+
isRscRequest: false,
10501051
incrementalCache: imageOptimizerCache,
10511052
isFallback: false,
10521053
}

packages/next/src/server/response-cache/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export default class ResponseCache implements ResponseCacheBase {
5353
responseGenerator: ResponseGenerator,
5454
context: {
5555
routeKind: RouteKind
56+
isRscRequest: boolean
5657
isOnDemandRevalidate?: boolean
5758
isPrefetch?: boolean
5859
incrementalCache: IncrementalResponseCache
@@ -198,6 +199,8 @@ export default class ResponseCache implements ResponseCacheBase {
198199
}
199200
)
200201

201-
return toResponseCacheEntry(response)
202+
return toResponseCacheEntry(response, {
203+
isRscRequest: context.isRscRequest,
204+
})
202205
}
203206
}

packages/next/src/server/response-cache/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export interface ResponseCacheBase {
1717
* provided it will test the filesystem to check.
1818
*/
1919
routeKind: RouteKind
20+
isRscRequest: boolean
2021

2122
/**
2223
* True if this is a fallback request.

packages/next/src/server/response-cache/utils.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99

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

1314
export async function fromResponseCacheEntry(
1415
cacheEntry: ResponseCacheEntry
@@ -39,7 +40,8 @@ export async function fromResponseCacheEntry(
3940
}
4041

4142
export async function toResponseCacheEntry(
42-
response: IncrementalResponseCacheEntry | null
43+
response: IncrementalResponseCacheEntry | null,
44+
{ isRscRequest }: { isRscRequest: boolean }
4345
): Promise<ResponseCacheEntry | null> {
4446
if (!response) return null
4547

@@ -62,7 +64,14 @@ export async function toResponseCacheEntry(
6264
html: RenderResult.fromStatic(response.value.html),
6365
rscData: response.value.rscData,
6466
headers: response.value.headers,
65-
status: response.value.status,
67+
status:
68+
// RSC redirect is embedded in the payload itself and handled by client router directly
69+
// This makes it consistent with how it's handled in minimalMode
70+
isRscRequest &&
71+
response.value.status &&
72+
RedirectStatusCode[response.value.status]
73+
? 200
74+
: response.value.status,
6675
postponed: response.value.postponed,
6776
segmentData: response.value.segmentData,
6877
} satisfies CachedAppPageValue)

0 commit comments

Comments
 (0)