Unverified Commit 06e7e76c authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Skip getStaticPaths check for non-dynamic app routes (#54351)

We don't need to apply this check for non-dynamic app routes so this
adds a check to skip it when not necessary.

x-ref: [slack
thread](https://vercel.slack.com/archives/C04DUD7EB1B/p1692366432958709)

---------
Co-authored-by: 's avatarZack Tanner <zacktanner@gmail.com>
parent 70231ef7
...@@ -1443,8 +1443,10 @@ export default abstract class Server<ServerOptions extends Options = Options> { ...@@ -1443,8 +1443,10 @@ export default abstract class Server<ServerOptions extends Options = Options> {
let staticPaths: string[] | undefined let staticPaths: string[] | undefined
let fallbackMode: FallbackMode let fallbackMode: FallbackMode
let hasFallback = false
const isDynamic = isDynamicRoute(components.pathname)
if (isAppPath) { if (isAppPath && isDynamic) {
const pathsResult = await this.getStaticPaths({ const pathsResult = await this.getStaticPaths({
pathname, pathname,
originalAppPath: components.pathname, originalAppPath: components.pathname,
...@@ -1453,44 +1455,40 @@ export default abstract class Server<ServerOptions extends Options = Options> { ...@@ -1453,44 +1455,40 @@ export default abstract class Server<ServerOptions extends Options = Options> {
staticPaths = pathsResult.staticPaths staticPaths = pathsResult.staticPaths
fallbackMode = pathsResult.fallbackMode fallbackMode = pathsResult.fallbackMode
hasFallback = typeof fallbackMode !== 'undefined'
const hasFallback = typeof fallbackMode !== 'undefined'
if (this.nextConfig.output === 'export') { if (this.nextConfig.output === 'export') {
const page = components.pathname const page = components.pathname
const isDynamic = isDynamicRoute(page)
if (isDynamic) { if (fallbackMode !== 'static') {
if (fallbackMode !== 'static') { throw new Error(
throw new Error( `Page "${page}" is missing exported function "generateStaticParams()", which is required with "output: export" config.`
`Page "${page}" is missing exported function "generateStaticParams()", which is required with "output: export" config.` )
) }
} const resolvedWithoutSlash = removeTrailingSlash(resolvedUrlPathname)
const resolvedWithoutSlash = removeTrailingSlash(resolvedUrlPathname) if (!staticPaths?.includes(resolvedWithoutSlash)) {
if (!staticPaths?.includes(resolvedWithoutSlash)) { throw new Error(
throw new Error( `Page "${page}" is missing param "${resolvedWithoutSlash}" in "generateStaticParams()", which is required with "output: export" config.`
`Page "${page}" is missing param "${resolvedWithoutSlash}" in "generateStaticParams()", which is required with "output: export" config.` )
)
}
} }
} }
if (hasFallback) { if (hasFallback) {
hasStaticPaths = true hasStaticPaths = true
} }
}
if ( if (
hasFallback || hasFallback ||
staticPaths?.includes(resolvedUrlPathname) || staticPaths?.includes(resolvedUrlPathname) ||
// this signals revalidation in deploy environments // this signals revalidation in deploy environments
// TODO: make this more generic // TODO: make this more generic
req.headers['x-now-route-matches'] req.headers['x-now-route-matches']
) { ) {
isSSG = true isSSG = true
} else if (!this.renderOpts.dev) { } else if (!this.renderOpts.dev) {
const manifest = this.getPrerenderManifest() const manifest = this.getPrerenderManifest()
isSSG = isSSG = isSSG || !!manifest.routes[pathname === '/index' ? '/' : pathname]
isSSG || !!manifest.routes[pathname === '/index' ? '/' : pathname]
}
} }
// Toggle whether or not this is a Data request // Toggle whether or not this is a Data request
......
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