Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from Oct 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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>
)
}