Unverified Commit d76d8270 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Update RSC detection in minimal mode and fix config collection (#41541)

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)
parent f055b167
...@@ -1051,14 +1051,14 @@ type GenerateParams = Array<{ ...@@ -1051,14 +1051,14 @@ type GenerateParams = Array<{
isLayout?: boolean isLayout?: boolean
}> }>
export const collectGenerateParams = ( export const collectGenerateParams = async (
segment: any, segment: any,
parentSegments: string[] = [], parentSegments: string[] = [],
generateParams: GenerateParams = [] generateParams: GenerateParams = []
): GenerateParams => { ): Promise<GenerateParams> => {
if (!Array.isArray(segment)) return generateParams if (!Array.isArray(segment)) return generateParams
const isLayout = !!segment[2]?.layout 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 = { const result = {
isLayout, isLayout,
...@@ -1264,7 +1264,7 @@ export async function isPageStatic({ ...@@ -1264,7 +1264,7 @@ export async function isPageStatic({
if (pageType === 'app') { if (pageType === 'app') {
const tree = componentsResult.ComponentMod.tree const tree = componentsResult.ComponentMod.tree
const generateParams = collectGenerateParams(tree) const generateParams = await collectGenerateParams(tree)
appConfig = generateParams.reduce( appConfig = generateParams.reduce(
(builtConfig: AppConfig, curGenParams): AppConfig => { (builtConfig: AppConfig, curGenParams): AppConfig => {
......
...@@ -483,6 +483,16 @@ export default abstract class Server<ServerOptions extends Options = Options> { ...@@ -483,6 +483,16 @@ export default abstract class Server<ServerOptions extends Options = Options> {
if (typeof parsedUrl.query === 'string') { if (typeof parsedUrl.query === 'string') {
parsedUrl.query = parseQs(parsedUrl.query) 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) req.url = normalizeRscPath(req.url, this.hasAppDir)
parsedUrl.pathname = normalizeRscPath( parsedUrl.pathname = normalizeRscPath(
parsedUrl.pathname || '', parsedUrl.pathname || '',
...@@ -1042,7 +1052,9 @@ export default abstract class Server<ServerOptions extends Options = Options> { ...@@ -1042,7 +1052,9 @@ export default abstract class Server<ServerOptions extends Options = Options> {
) )
if (isSSG && req.headers['__rsc__']) { if (isSSG && req.headers['__rsc__']) {
isDataReq = true if (!this.minimalMode) {
isDataReq = true
}
// strip header so we generate HTML still // strip header so we generate HTML still
if ( if (
opts.runtime !== 'experimental-edge' || opts.runtime !== 'experimental-edge' ||
......
...@@ -80,7 +80,9 @@ export async function loadStaticPaths({ ...@@ -80,7 +80,9 @@ export async function loadStaticPaths({
workerWasUsed = true workerWasUsed = true
if (isAppPath) { if (isAppPath) {
const generateParams = collectGenerateParams(components.ComponentMod.tree) const generateParams = await collectGenerateParams(
components.ComponentMod.tree
)
return buildAppStaticPaths({ return buildAppStaticPaths({
page: pathname, page: pathname,
generateParams, generateParams,
......
...@@ -41,6 +41,7 @@ describe('app-dir static/dynamic handling', () => { ...@@ -41,6 +41,7 @@ describe('app-dir static/dynamic handling', () => {
).filter((file) => file.match(/.*\.(js|html|rsc)$/)) ).filter((file) => file.match(/.*\.(js|html|rsc)$/))
expect(files).toEqual([ expect(files).toEqual([
'(new)/custom/page.js',
'blog/[author]/[slug]/page.js', 'blog/[author]/[slug]/page.js',
'blog/[author]/page.js', 'blog/[author]/page.js',
'blog/seb.html', 'blog/seb.html',
......
export const config = {
revalidate: 0,
}
export default function Page() {
return <p>new root ssr</p>
}
export default function Layout({ children }) {
return (
<html lang="en">
<head>
<title>my static blog</title>
</head>
<body>{children}</body>
</html>
)
}
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