[next] fix content-type for RSC prefetches (#10487)

This ensures that the `.prefetch.rsc` requests respond with the correct `content-type` since this is used by Next.js to determine if a request is valid or not (and in the case it's invalid, an mpa navigation will occur)

Fixes: https://github.com/vercel/next.js/issues/54934
This commit is contained in:
Zack Tanner
2023-09-11 12:04:16 -07:00
committed by GitHub
parent 8504735808
commit a732d30c84
4 changed files with 35 additions and 8 deletions

View File

@@ -48,6 +48,9 @@ export const MIB = 1024 * KIB;
export const prettyBytes = (n: number) => bytes(n, { unitSeparator: ' ' });
export const RSC_CONTENT_TYPE = 'x-component';
export const RSC_PREFETCH_SUFFIX = '.prefetch.rsc';
// Identify /[param]/ in route string
// eslint-disable-next-line no-useless-escape
const TEST_DYNAMIC_ROUTE = /\/\[[^\/]+?\](?=\/|$)/;
@@ -2158,7 +2161,7 @@ export const onPrerenderRoute =
routesManifest?.rsc?.varyHeader ||
'RSC, Next-Router-State-Tree, Next-Router-Prefetch';
const rscContentTypeHeader =
routesManifest?.rsc?.contentTypeHeader || 'text/x-component';
routesManifest?.rsc?.contentTypeHeader || RSC_CONTENT_TYPE;
let sourcePath: string | undefined;
if (`/${outputPathPage}` !== srcRoute && srcRoute) {