Skip to content

Commit

Permalink
Skip getStaticPaths check for non-dynamic app routes (#54351)
Browse files Browse the repository at this point in the history
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: Zack Tanner <zacktanner@gmail.com>
  • Loading branch information
ijjk and ztanner committed Aug 21, 2023
1 parent 70231ef commit 06e7e76
Showing 1 changed file with 27 additions and 29 deletions.
56 changes: 27 additions & 29 deletions packages/next/src/server/base-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1443,8 +1443,10 @@ export default abstract class Server<ServerOptions extends Options = Options> {
let staticPaths: string[] | undefined

let fallbackMode: FallbackMode
let hasFallback = false
const isDynamic = isDynamicRoute(components.pathname)

if (isAppPath) {
if (isAppPath && isDynamic) {
const pathsResult = await this.getStaticPaths({
pathname,
originalAppPath: components.pathname,
Expand All @@ -1453,44 +1455,40 @@ export default abstract class Server<ServerOptions extends Options = Options> {

staticPaths = pathsResult.staticPaths
fallbackMode = pathsResult.fallbackMode

const hasFallback = typeof fallbackMode !== 'undefined'
hasFallback = typeof fallbackMode !== 'undefined'

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 (
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]
}

// Toggle whether or not this is a Data request
Expand Down

0 comments on commit 06e7e76

Please sign in to comment.