Skip to content

Commit a2d8598

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

File tree

5 files changed

+23
-4
lines changed

5 files changed

+23
-4
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3051,7 +3051,9 @@ export default abstract class Server<
30513051
// the previous fallback cache entry. This preserves the previous
30523052
// behavior.
30533053
if (isProduction) {
3054-
return toResponseCacheEntry(previousFallbackCacheEntry)
3054+
return toResponseCacheEntry(previousFallbackCacheEntry, {
3055+
isRscRequest: isRSCRequest,
3056+
})
30553057
}
30563058

30573059
// We pass `undefined` and `null` as it doesn't apply to the pages
@@ -3067,6 +3069,7 @@ export default abstract class Server<
30673069
},
30683070
{
30693071
routeKind: RouteKind.PAGES,
3072+
isRscRequest: isRSCRequest,
30703073
incrementalCache,
30713074
isRoutePPREnabled,
30723075
isFallback: true,
@@ -3101,6 +3104,7 @@ export default abstract class Server<
31013104
}),
31023105
{
31033106
routeKind: RouteKind.APP_PAGE,
3107+
isRscRequest: isRSCRequest,
31043108
incrementalCache,
31053109
isRoutePPREnabled,
31063110
isFallback: true,
@@ -3173,6 +3177,7 @@ export default abstract class Server<
31733177
// rendered and thus check isAppPath.
31743178
routeModule?.definition.kind ??
31753179
(isAppPath ? RouteKind.APP_PAGE : RouteKind.PAGES),
3180+
isRscRequest: isRSCRequest,
31763181
incrementalCache,
31773182
isOnDemandRevalidate,
31783183
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)