mirror of
https://github.com/hanzoai/next.js.git
synced 2026-10-30 14:46:38 +00:00
### What? This PR adds build-time validation that requires `generateStaticParams` to return at least one result when Cache Components (experimental `cacheComponents` feature) is enabled. ### Why? Previously, users could return an empty array (`[]`) from `generateStaticParams` to indicate a route should be treated statically without providing specific parameter values. This pattern has a critical issue with Cache Components: **The Problem:** - With Cache Components enabled, accessing `params` is treated as a dynamic API usage - When `generateStaticParams` returns empty results, Next.js cannot perform build-time validation to detect if the route accesses other dynamic APIs (like `await cookies()`, `await headers()`, or `await searchParams`) - This means users could successfully build routes that would fail at runtime with dynamic API errors **The Solution:** - By requiring at least one parameter value, we can execute the route during build time with real params - This allows us to validate that the route doesn't make additional dynamic API calls that would cause runtime failures - Build-time validation catches configuration errors early, before deployment ### How? - Modified `buildAppStaticPaths` in `packages/next/src/build/static-paths/app.ts` to check if PPR is enabled and throw error when `generateStaticParams` returns empty array with Cache Components enabled - Added comprehensive error documentation at `errors/empty-generate-static-params.mdx` with migration options Migration paths provided in error documentation: 1. Return at least one real param (recommended) 2. Use placeholder params (not recommended, bypasses validation) The breaking change is acceptable because `cacheComponents` is still experimental and only available in canary releases. ### Related - Addresses discrepancy discovered with https://github.com/vercel/next.js/discussions/84925. - Fixes https://github.com/vercel/next.js/issues/84801
16 lines
414 B
TypeScript
16 lines
414 B
TypeScript
export async function generateStaticParams() {
|
|
return [{ lang: 'en', flags: 'us', rest: ['home'] }]
|
|
}
|
|
|
|
export default async function Page(props) {
|
|
const params = await props.params
|
|
|
|
return (
|
|
<div>
|
|
<div data-lang={params.lang}>{params.lang}</div>
|
|
<div data-flags={params.flags}>{params.flags}</div>
|
|
<div data-rest={params.rest?.join('/')}>{params.rest?.join('/')}</div>
|
|
</div>
|
|
)
|
|
}
|