AI & Agent Dev Bug Sandbox logo
AI & Agent Dev Bug Sandbox
Back to Radar

Child `GenerateStaticParams` Returning Empty Array For Some Parent Params Causes All Static Params To Be Dropped

When a nested child `generateStaticParams` returns an empty array for a subset of parent parameter values, Next.js build incorrectly discards all static params for that route, including valid non-empty results from other parent values. This results in missing pre-rendered pages despite the route being marked as SSG.

highConfidence 92%Next.jsAffected V16.2.4Affected V16.2.9Affected V16.3.0-Canary.67

Origin Analysis

In Next.js's `collectGenerateParams` (packages/next/src/build/utils.ts), the build process prematurely returns an empty result for an entire dynamic segment when a child `generateStaticParams` returns `[]` for a specific parent parameter combination. This early bail-out does not continue iterating over other parent parameter sets, so valid static entries from sibling parent values are lost.
1. Create a parent dynamic segment `[lang]` whose layout `generateStaticParams` returns `[{ lang: 'en' }, { lang: 'fr' }]`. 2. Create a child dynamic segment `[slug]` whose page `generateStaticParams` returns non-empty slugs for 'en' and `[]` for 'fr'. 3. Create a control child route that returns non-empty slugs for both parents. 4. Run `next build` and observe that the bug route produces zero HTML files while the control route produces four.

Fixing Code Block

Edge Case Audit

This patch changes the behavior for routes that intentionally return an empty array from `generateStaticParams` at the top level to opt out of static generation entirely. Such routes may now be treated as dynamic rather than producing zero static pages. Test dynamic fallback, catch-all routes, and cases where all parent combinations return empty to ensure no unintended changes. Rollback: keep a backup of the original `collectGenerateParams` function and revert if dynamic rendering behavior regresses.

Ecosystem Topology