Unverified Commit 5fbf29ca authored by Wyatt Johnson's avatar Wyatt Johnson Committed by GitHub

fix: remove boundary sentinel from RSC responses (#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
parent 443a31b9
...@@ -32,6 +32,7 @@ import { ...@@ -32,6 +32,7 @@ import {
NEXT_ROUTER_PREFETCH_HEADER, NEXT_ROUTER_PREFETCH_HEADER,
NEXT_IS_PRERENDER_HEADER, NEXT_IS_PRERENDER_HEADER,
NEXT_DID_POSTPONE_HEADER, NEXT_DID_POSTPONE_HEADER,
RSC_CONTENT_TYPE_HEADER,
} from '../../client/components/app-router-headers' } from '../../client/components/app-router-headers'
import { getBotType, isBot } from '../../shared/lib/router/utils/is-bot' import { getBotType, isBot } from '../../shared/lib/router/utils/is-bot'
import { import {
...@@ -1074,11 +1075,19 @@ export async function handler( ...@@ -1074,11 +1075,19 @@ export async function handler(
// If there's no postponed state, we should just serve the HTML. This // If there's no postponed state, we should just serve the HTML. This
// should also be the case for a resume request because it's completed // should also be the case for a resume request because it's completed
// as a server render (rather than a static render). // as a server render (rather than a static render).
if (!didPostpone || minimalMode) { if (!didPostpone || minimalMode || isRSCRequest) {
// If we're in test mode, we should add a sentinel chunk to the response // If we're in test mode, we should add a sentinel chunk to the response
// that's between the static and dynamic parts so we can compare the // that's between the static and dynamic parts so we can compare the
// chunks and add assertions. // chunks and add assertions.
if (process.env.__NEXT_TEST_MODE && minimalMode && isRoutePPREnabled) { if (
process.env.__NEXT_TEST_MODE &&
minimalMode &&
isRoutePPREnabled &&
// If the response body is an RSC content type of the request was for
// an RSC request then we shouldn't add the sentinel.
body.contentType !== RSC_CONTENT_TYPE_HEADER &&
!isRSCRequest
) {
// As we're in minimal mode, the static part would have already been // As we're in minimal mode, the static part would have already been
// streamed first. The only part that this streams is the dynamic part // streamed first. The only part that this streams is the dynamic part
// so we should FIRST stream the sentinel and THEN the dynamic part. // so we should FIRST stream the sentinel and THEN the dynamic part.
...@@ -1088,7 +1097,7 @@ export async function handler( ...@@ -1088,7 +1097,7 @@ export async function handler(
return sendRenderResult({ return sendRenderResult({
req, req,
res, res,
type: 'html', type: isRSCRequest ? 'rsc' : 'html',
generateEtags: nextConfig.generateEtags, generateEtags: nextConfig.generateEtags,
poweredByHeader: nextConfig.poweredByHeader, poweredByHeader: nextConfig.poweredByHeader,
result: body, result: body,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment