Skip to content

Commit

Permalink
Update RSC detection in minimal mode and fix config collection (#41541)
Browse files Browse the repository at this point in the history
Updates our RSC detection for revalidation in minimal mode and also ensures we await import promises when collecting app dir config. 

x-ref: [slack thread](https://vercel.slack.com/archives/C035J346QQL/p1666202250144319)
x-ref: [slack thread](https://vercel.slack.com/archives/C035J346QQL/p1666125853222599?thread_ts=1666122861.189349&cid=C035J346QQL)
  • Loading branch information
ijjk committed Oct 19, 2022
1 parent f055b16 commit d76d827
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 6 deletions.
8 changes: 4 additions & 4 deletions packages/next/build/utils.ts
Expand Up @@ -1051,14 +1051,14 @@ type GenerateParams = Array<{
isLayout?: boolean
}>

export const collectGenerateParams = (
export const collectGenerateParams = async (
segment: any,
parentSegments: string[] = [],
generateParams: GenerateParams = []
): GenerateParams => {
): Promise<GenerateParams> => {
if (!Array.isArray(segment)) return generateParams
const isLayout = !!segment[2]?.layout
const mod = isLayout ? segment[2]?.layout?.() : segment[2]?.page?.()
const mod = await (isLayout ? segment[2]?.layout?.() : segment[2]?.page?.())

const result = {
isLayout,
Expand Down Expand Up @@ -1264,7 +1264,7 @@ export async function isPageStatic({

if (pageType === 'app') {
const tree = componentsResult.ComponentMod.tree
const generateParams = collectGenerateParams(tree)
const generateParams = await collectGenerateParams(tree)

appConfig = generateParams.reduce(
(builtConfig: AppConfig, curGenParams): AppConfig => {
Expand Down
14 changes: 13 additions & 1 deletion packages/next/server/base-server.ts
Expand Up @@ -483,6 +483,16 @@ export default abstract class Server<ServerOptions extends Options = Options> {
if (typeof parsedUrl.query === 'string') {
parsedUrl.query = parseQs(parsedUrl.query)
}
// in minimal mode we detect RSC revalidate if the .rsc path is requested
if (
this.minimalMode &&
(req.url.endsWith('.rsc') ||
(typeof req.headers['x-matched-path'] === 'string' &&
req.headers['x-matched-path'].endsWith('.rsc')))
) {
parsedUrl.query.__nextDataReq = '1'
}

req.url = normalizeRscPath(req.url, this.hasAppDir)
parsedUrl.pathname = normalizeRscPath(
parsedUrl.pathname || '',
Expand Down Expand Up @@ -1042,7 +1052,9 @@ export default abstract class Server<ServerOptions extends Options = Options> {
)

if (isSSG && req.headers['__rsc__']) {
isDataReq = true
if (!this.minimalMode) {
isDataReq = true
}
// strip header so we generate HTML still
if (
opts.runtime !== 'experimental-edge' ||
Expand Down
4 changes: 3 additions & 1 deletion packages/next/server/dev/static-paths-worker.ts
Expand Up @@ -80,7 +80,9 @@ export async function loadStaticPaths({
workerWasUsed = true

if (isAppPath) {
const generateParams = collectGenerateParams(components.ComponentMod.tree)
const generateParams = await collectGenerateParams(
components.ComponentMod.tree
)
return buildAppStaticPaths({
page: pathname,
generateParams,
Expand Down
1 change: 1 addition & 0 deletions test/e2e/app-dir/app-static.test.ts
Expand Up @@ -41,6 +41,7 @@ describe('app-dir static/dynamic handling', () => {
).filter((file) => file.match(/.*\.(js|html|rsc)$/))

expect(files).toEqual([
'(new)/custom/page.js',
'blog/[author]/[slug]/page.js',
'blog/[author]/page.js',
'blog/seb.html',
Expand Down
7 changes: 7 additions & 0 deletions test/e2e/app-dir/app-static/app/(new)/custom/page.js
@@ -0,0 +1,7 @@
export const config = {
revalidate: 0,
}

export default function Page() {
return <p>new root ssr</p>
}
10 changes: 10 additions & 0 deletions test/e2e/app-dir/app-static/app/(new)/layout.js
@@ -0,0 +1,10 @@
export default function Layout({ children }) {
return (
<html lang="en">
<head>
<title>my static blog</title>
</head>
<body>{children}</body>
</html>
)
}

0 comments on commit d76d827

Please sign in to comment.