Skip to content

Commit 6144f6b

Browse files
wyattjohalii
authored andcommitted
fix: remove boundary sentinel from RSC responses (vercel#81857)
## Summary This PR fixes an issue where the test mode boundary sentinel was being incorrectly added to RSC (React Server Component) responses. The sentinel should only be added to HTML responses during PPR (Partial Prerendering) test mode. ## Changes - Added check to prevent boundary sentinel insertion when the response is an RSC content type - Added check to prevent boundary sentinel insertion when the request is an RSC request - Correctly set the response type to 'rsc' instead of 'html' for RSC requests ## Test plan - [x] Existing tests should pass - [x] RSC responses should not contain the test mode boundary sentinel - [x] HTML responses in PPR test mode should still contain the boundary sentinel as expected
1 parent 1a1fcad commit 6144f6b

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

packages/next/src/build/templates/app-page.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import {
3232
NEXT_ROUTER_PREFETCH_HEADER,
3333
NEXT_IS_PRERENDER_HEADER,
3434
NEXT_DID_POSTPONE_HEADER,
35+
RSC_CONTENT_TYPE_HEADER,
3536
} from '../../client/components/app-router-headers'
3637
import { getBotType, isBot } from '../../shared/lib/router/utils/is-bot'
3738
import {
@@ -1074,11 +1075,19 @@ export async function handler(
10741075
// If there's no postponed state, we should just serve the HTML. This
10751076
// should also be the case for a resume request because it's completed
10761077
// as a server render (rather than a static render).
1077-
if (!didPostpone || minimalMode) {
1078+
if (!didPostpone || minimalMode || isRSCRequest) {
10781079
// If we're in test mode, we should add a sentinel chunk to the response
10791080
// that's between the static and dynamic parts so we can compare the
10801081
// chunks and add assertions.
1081-
if (process.env.__NEXT_TEST_MODE && minimalMode && isRoutePPREnabled) {
1082+
if (
1083+
process.env.__NEXT_TEST_MODE &&
1084+
minimalMode &&
1085+
isRoutePPREnabled &&
1086+
// If the response body is an RSC content type of the request was for
1087+
// an RSC request then we shouldn't add the sentinel.
1088+
body.contentType !== RSC_CONTENT_TYPE_HEADER &&
1089+
!isRSCRequest
1090+
) {
10821091
// As we're in minimal mode, the static part would have already been
10831092
// streamed first. The only part that this streams is the dynamic part
10841093
// so we should FIRST stream the sentinel and THEN the dynamic part.
@@ -1088,7 +1097,7 @@ export async function handler(
10881097
return sendRenderResult({
10891098
req,
10901099
res,
1091-
type: 'html',
1100+
type: isRSCRequest ? 'rsc' : 'html',
10921101
generateEtags: nextConfig.generateEtags,
10931102
poweredByHeader: nextConfig.poweredByHeader,
10941103
result: body,

0 commit comments

Comments
 (0)