Skip to content

Commit

Permalink
fix: rsc content-type header not matching with charset (#70033)
Browse files Browse the repository at this point in the history
`charset` can be included in the `content-type` header which currently
causes `RSC` detection to fail when it shouldn't so this relaxes the
check to just ensure the RSC `content-type` includes the expected type
not an exact match.

---------

Co-authored-by: JJ Kasper <jj@jjsweb.site>
  • Loading branch information
ImDR and ijjk authored Sep 16, 2024
1 parent 3842680 commit 02f886a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ export async function fetchServerResponse(
const interception = !!res.headers.get('vary')?.includes(NEXT_URL)
const isPrerender = !!res.headers.get(NEXT_IS_PRERENDER_HEADER)
const postponed = !!res.headers.get(NEXT_DID_POSTPONE_HEADER)
let isFlightResponse = contentType === RSC_CONTENT_TYPE_HEADER
let isFlightResponse = contentType.startsWith(RSC_CONTENT_TYPE_HEADER)

if (process.env.NODE_ENV === 'production') {
if (process.env.__NEXT_CONFIG_OUTPUT === 'export') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ async function fetchServerAction(

const contentType = res.headers.get('content-type')

if (contentType === RSC_CONTENT_TYPE_HEADER) {
if (contentType?.startsWith(RSC_CONTENT_TYPE_HEADER)) {
const response: ActionFlightResponse = await createFromFetch(
Promise.resolve(res),
{
Expand Down
10 changes: 8 additions & 2 deletions packages/next/src/server/app-render/action-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,9 @@ async function createForwardedActionResponse(
},
})

if (response.headers.get('content-type') === RSC_CONTENT_TYPE_HEADER) {
if (
response.headers.get('content-type')?.startsWith(RSC_CONTENT_TYPE_HEADER)
) {
// copy the headers from the redirect response to the response we're sending
for (const [key, value] of response.headers) {
if (!actionsForbiddenHeaders.includes(key)) {
Expand Down Expand Up @@ -340,7 +342,11 @@ async function createRedirectRenderResult(
},
})

if (response.headers.get('content-type') === RSC_CONTENT_TYPE_HEADER) {
if (
response.headers
.get('content-type')
?.startsWith(RSC_CONTENT_TYPE_HEADER)
) {
// copy the headers from the redirect response to the response we're sending
for (const [key, value] of response.headers) {
if (!actionsForbiddenHeaders.includes(key)) {
Expand Down

0 comments on commit 02f886a

Please sign in to comment.