Skip to content

Commit

Permalink
[next] Update rsc header handling (#8862)
Browse files Browse the repository at this point in the history
### Related Issues

Required for vercel/next.js#42482

### 📋 Checklist

<!--
  Please keep your PR as a Draft until the checklist is complete
-->

#### Tests

- [ ] The code changed/added as part of this PR has been covered with
tests
- [ ] All tests pass locally with `yarn test-unit`

#### Code Review

- [ ] This PR has a concise title and thorough description useful to a
reviewer
- [ ] Issue from task tracker has a link to this PR
  • Loading branch information
ijjk committed Nov 7, 2022
1 parent 832ba3f commit 9618ffe
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
6 changes: 4 additions & 2 deletions packages/next/src/server-build.ts
Expand Up @@ -1137,6 +1137,8 @@ export async function serverBuild({
}
}

const rscHeader = routesManifest.rsc?.header || '__rsc__';

return {
wildcard: wildcardConfig,
images:
Expand Down Expand Up @@ -1390,7 +1392,7 @@ export async function serverBuild({
has: [
{
type: 'header',
key: '__rsc__',
key: rscHeader,
},
],
dest: path.posix.join('/', entryDirectory, '/index.rsc'),
Expand All @@ -1401,7 +1403,7 @@ export async function serverBuild({
has: [
{
type: 'header',
key: '__rsc__',
key: rscHeader,
},
],
dest: path.posix.join('/', entryDirectory, '/$1.rsc'),
Expand Down
11 changes: 9 additions & 2 deletions packages/next/src/utils.ts
Expand Up @@ -209,6 +209,10 @@ type RoutesManifestOld = {
defaultLocale: string;
}>;
};
rsc?: {
header: string;
varyHeader: string;
};
};

type RoutesManifestV4 = Omit<RoutesManifestOld, 'dynamicRoutes' | 'version'> & {
Expand Down Expand Up @@ -1991,6 +1995,9 @@ export const onPrerenderRoute =
allowQuery = [];
}
}
const rscVaryHeader =
routesManifest?.rsc?.varyHeader ||
'__rsc__, __next_router_state_tree__, __next_router_prefetch__';

prerenders[outputPathPage] = new Prerender({
expiration: initialRevalidate,
Expand All @@ -2008,7 +2015,7 @@ export const onPrerenderRoute =
...(isAppPathRoute
? {
initialHeaders: {
vary: '__rsc__, __next_router_state_tree__, __next_router_prefetch__',
vary: rscVaryHeader,
},
}
: {}),
Expand All @@ -2031,7 +2038,7 @@ export const onPrerenderRoute =
? {
initialHeaders: {
'content-type': 'application/octet-stream',
vary: '__rsc__, __next_router_state_tree__, __next_router_prefetch__',
vary: rscVaryHeader,
},
}
: {}),
Expand Down

0 comments on commit 9618ffe

Please sign in to comment.