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<{
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,
......@@ -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 => {
......
......@@ -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 || '',
......@@ -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' ||
......
......@@ -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,
......
......@@ -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',
......
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