From 022c452d3d96c9b65178b708306d89a768572aba Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Mon, 21 Aug 2023 11:15:35 -0700 Subject: [PATCH 1/4] Skip getStaticPaths check for non-dynamic app routes --- packages/next/src/server/base-server.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/next/src/server/base-server.ts b/packages/next/src/server/base-server.ts index 6a6febecd39f0..b5963b279e8a4 100644 --- a/packages/next/src/server/base-server.ts +++ b/packages/next/src/server/base-server.ts @@ -1444,7 +1444,7 @@ export default abstract class Server { let fallbackMode: FallbackMode - if (isAppPath) { + if (isAppPath && isDynamicRoute(pathname)) { const pathsResult = await this.getStaticPaths({ pathname, originalAppPath: components.pathname, From 713051e0d02179bfc218397f5bea7756d6bca3fc Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Mon, 21 Aug 2023 14:05:48 -0700 Subject: [PATCH 2/4] tweak --- packages/next/src/server/base-server.ts | 52 ++++++++++++------------- 1 file changed, 25 insertions(+), 27 deletions(-) diff --git a/packages/next/src/server/base-server.ts b/packages/next/src/server/base-server.ts index b5963b279e8a4..e1779165120ef 100644 --- a/packages/next/src/server/base-server.ts +++ b/packages/next/src/server/base-server.ts @@ -1443,8 +1443,9 @@ export default abstract class Server { let staticPaths: string[] | undefined let fallbackMode: FallbackMode + const isDynamic = isDynamicRoute(components.pathname) - if (isAppPath && isDynamicRoute(pathname)) { + if (isAppPath && isDynamic) { const pathsResult = await this.getStaticPaths({ pathname, originalAppPath: components.pathname, @@ -1458,39 +1459,36 @@ export default abstract class Server { if (this.nextConfig.output === 'export') { const page = components.pathname - const isDynamic = isDynamicRoute(page) - if (isDynamic) { - if (fallbackMode !== 'static') { - throw new Error( - `Page "${page}" is missing exported function "generateStaticParams()", which is required with "output: export" config.` - ) - } - const resolvedWithoutSlash = removeTrailingSlash(resolvedUrlPathname) - if (!staticPaths?.includes(resolvedWithoutSlash)) { - throw new Error( - `Page "${page}" is missing param "${resolvedWithoutSlash}" in "generateStaticParams()", which is required with "output: export" config.` - ) - } + + if (fallbackMode !== 'static') { + throw new Error( + `Page "${page}" is missing exported function "generateStaticParams()", which is required with "output: export" config.` + ) + } + const resolvedWithoutSlash = removeTrailingSlash(resolvedUrlPathname) + if (!staticPaths?.includes(resolvedWithoutSlash)) { + throw new Error( + `Page "${page}" is missing param "${resolvedWithoutSlash}" in "generateStaticParams()", which is required with "output: export" config.` + ) } } if (hasFallback) { hasStaticPaths = true } + } - if ( - hasFallback || - staticPaths?.includes(resolvedUrlPathname) || - // this signals revalidation in deploy environments - // TODO: make this more generic - req.headers['x-now-route-matches'] - ) { - isSSG = true - } else if (!this.renderOpts.dev) { - const manifest = this.getPrerenderManifest() - isSSG = - isSSG || !!manifest.routes[pathname === '/index' ? '/' : pathname] - } + if ( + typeof fallbackMode !== 'undefined' || + staticPaths?.includes(resolvedUrlPathname) || + // this signals revalidation in deploy environments + // TODO: make this more generic + req.headers['x-now-route-matches'] + ) { + isSSG = true + } else if (!this.renderOpts.dev) { + const manifest = this.getPrerenderManifest() + isSSG = isSSG || !!manifest.routes[pathname === '/index' ? '/' : pathname] } // Toggle whether or not this is a Data request From f8bc61dd267054f19395721da2f89b01b5c55ed3 Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Mon, 21 Aug 2023 14:24:22 -0700 Subject: [PATCH 3/4] Apply suggestions from code review Co-authored-by: Zack Tanner --- packages/next/src/server/base-server.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/next/src/server/base-server.ts b/packages/next/src/server/base-server.ts index e1779165120ef..569b46f60b45c 100644 --- a/packages/next/src/server/base-server.ts +++ b/packages/next/src/server/base-server.ts @@ -1479,7 +1479,7 @@ export default abstract class Server { } if ( - typeof fallbackMode !== 'undefined' || + hasFallback || staticPaths?.includes(resolvedUrlPathname) || // this signals revalidation in deploy environments // TODO: make this more generic From 76521257fe92b6b07e6b1f607f631997a56f3a09 Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Mon, 21 Aug 2023 14:25:09 -0700 Subject: [PATCH 4/4] hoist --- packages/next/src/server/base-server.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/next/src/server/base-server.ts b/packages/next/src/server/base-server.ts index 569b46f60b45c..426c1772a06b5 100644 --- a/packages/next/src/server/base-server.ts +++ b/packages/next/src/server/base-server.ts @@ -1443,6 +1443,7 @@ export default abstract class Server { let staticPaths: string[] | undefined let fallbackMode: FallbackMode + let hasFallback = false const isDynamic = isDynamicRoute(components.pathname) if (isAppPath && isDynamic) { @@ -1454,8 +1455,7 @@ export default abstract class Server { staticPaths = pathsResult.staticPaths fallbackMode = pathsResult.fallbackMode - - const hasFallback = typeof fallbackMode !== 'undefined' + hasFallback = typeof fallbackMode !== 'undefined' if (this.nextConfig.output === 'export') { const page = components.pathname