Skip to content

Commit

Permalink
await promise for app mod when collecting config
Browse files Browse the repository at this point in the history
  • Loading branch information
ijjk committed Oct 19, 2022
1 parent f8e1a76 commit 6e41ef4
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 5 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
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 6e41ef4

Please sign in to comment.