diff --git a/packages/next/src/build/index.ts b/packages/next/src/build/index.ts index a3259c6fec12a..ffb0b7cc7126a 100644 --- a/packages/next/src/build/index.ts +++ b/packages/next/src/build/index.ts @@ -1494,7 +1494,8 @@ export default async function build( isSsg = true } if ( - !isDynamicRoute(page) && + (!isDynamicRoute(page) || + !workerResult.prerenderRoutes?.length) && workerResult.appConfig?.revalidate !== 0 ) { appStaticPaths.set(originalAppPath, [page]) @@ -2360,6 +2361,8 @@ export default async function build( let hasDynamicData = appConfig.revalidate === 0 routes.forEach((route) => { + if (isDynamicRoute(page) && route === page) return + let revalidate = exportConfig.initialPageRevalidationMap[route] if (typeof revalidate === 'undefined') { diff --git a/packages/next/src/build/utils.ts b/packages/next/src/build/utils.ts index 22fe2daf5fc87..49c1f1da010fb 100644 --- a/packages/next/src/build/utils.ts +++ b/packages/next/src/build/utils.ts @@ -1191,7 +1191,10 @@ export async function buildAppStaticPaths({ if (!hadGenerateParams) { return { paths: undefined, - fallback: undefined, + fallback: + process.env.NODE_ENV === 'production' && isDynamicRoute(page) + ? true + : undefined, encodedPaths: undefined, } } diff --git a/test/e2e/app-dir/app-static/app-static.test.ts b/test/e2e/app-dir/app-static/app-static.test.ts index c08c636b8f9a4..9a059306befb5 100644 --- a/test/e2e/app-dir/app-static/app-static.test.ts +++ b/test/e2e/app-dir/app-static/app-static.test.ts @@ -43,6 +43,8 @@ createNextDescribe( 'dynamic-error.rsc', 'dynamic-error/page.js', 'dynamic-no-gen-params-ssr/[slug]/page.js', + 'dynamic-no-gen-params/[slug].html', + 'dynamic-no-gen-params/[slug].rsc', 'dynamic-no-gen-params/[slug]/page.js', 'force-static/[slug]/page.js', 'force-static/first.html', @@ -201,6 +203,16 @@ createNextDescribe( fallback: false, routeRegex: normalizeRegEx('^\\/blog\\/([^\\/]+?)(?:\\/)?$'), }, + '/dynamic-no-gen-params/[slug]': { + dataRoute: '/dynamic-no-gen-params/[slug].rsc', + dataRouteRegex: normalizeRegEx( + '^\\/dynamic\\-no\\-gen\\-params\\/([^\\/]+?)\\.rsc$' + ), + fallback: null, + routeRegex: normalizeRegEx( + '^\\/dynamic\\-no\\-gen\\-params\\/([^\\/]+?)(?:\\/)?$' + ), + }, '/hooks/use-pathname/[slug]': { dataRoute: '/hooks/use-pathname/[slug].rsc', dataRouteRegex: '^\\/hooks\\/use\\-pathname\\/([^\\/]+?)\\.rsc$',