Download nextjs-generate-static-params-validation/solution/gold.patch from dari-ai/nextjs-selfbench: direct link, hf CLI and curl.
- Browser
- Download file 4 kB
-
https://huggingface.co/datasets/dari-ai/nextjs-selfbench/resolve/main/nextjs-generate-static-params-validation/solution/gold.patch
- Command line
-
hf download hf://datasets/dari-ai/nextjs-selfbench/nextjs-generate-static-params-validation/solution/gold.patch
-
curl -L -o gold.patch https://huggingface.co/datasets/dari-ai/nextjs-selfbench/resolve/main/nextjs-generate-static-params-validation/solution/gold.patch
4 kB
| diff --git a/packages/next/errors.json b/packages/next/errors.json | |
| index d4e19f0cb8..a7297d7c0c 100644 | |
| --- a/packages/next/errors.json | |
| +++ b/packages/next/errors.json | |
| "1446": "Missing initURL", | |
| "1447": "Could not determine origin for forwarded Server Actions request. This can happen if port or hostname are not configured for this server.", | |
| "1448": "Error in the \"%s\" app-route HMR subscription", | |
| - "1449": "Accessed `searchParams` during prerendering." | |
| + "1449": "Accessed `searchParams` during prerendering.", | |
| + "1450": "Invalid value returned from generateStaticParams for \"%s\". Expected an array, but received type %s. See more info here: https://nextjs.org/docs/messages/generate-static-params", | |
| + "1451": "Invalid value at index %s returned from generateStaticParams for \"%s\". Expected an object, but received type %s. See more info here: https://nextjs.org/docs/messages/generate-static-params" | |
| } | |
| diff --git a/packages/next/src/build/static-paths/app.ts b/packages/next/src/build/static-paths/app.ts | |
| index 4e0c84ebc9..a9c35e8853 100644 | |
| --- a/packages/next/src/build/static-paths/app.ts | |
| +++ b/packages/next/src/build/static-paths/app.ts | |
| import { throwEmptyGenerateStaticParamsError } from '../../shared/lib/errors/emp | |
| import type { AppRouteModule } from '../../server/route-modules/app-route/module.compiled' | |
| import type { NormalizedAppRoute } from '../../shared/lib/router/routes/app' | |
| import { interceptionPrefixFromParamType } from '../../shared/lib/router/utils/interception-prefix-from-param-type' | |
| +import { isPlainObject } from '../../shared/lib/is-plain-object' | |
| import { | |
| type GenerateStaticParamsStore, | |
| workUnitAsyncStorage, | |
| export function assignStaticShellMetadata( | |
| } | |
| } | |
| +function getValueType(value: unknown): string { | |
| + if (value === null) return 'null' | |
| + if (Array.isArray(value)) return 'array' | |
| + return typeof value | |
| +} | |
| + | |
| /** | |
| * Calls a single generateStaticParams function within a WorkUnitStore context, | |
| * making root param getters available during static param generation. | |
| */ | |
| async function callGenerateStaticParams( | |
| + page: string, | |
| generateStaticParams: NonNullable<AppSegment['generateStaticParams']>, | |
| parentParams: Params, | |
| rootParamKeys: readonly string[], | |
| async function callGenerateStaticParams( | |
| rootParams, | |
| } | |
| - return workUnitAsyncStorage.run(workUnitStore, generateStaticParams, { | |
| - params: parentParams, | |
| - }) | |
| + const generatedParams: unknown = await workUnitAsyncStorage.run( | |
| + workUnitStore, | |
| + generateStaticParams, | |
| + { params: parentParams } | |
| + ) | |
| + | |
| + if (!Array.isArray(generatedParams)) { | |
| + throw new Error( | |
| + `Invalid value returned from generateStaticParams for "${page}". Expected an array, but received type ${getValueType(generatedParams)}. See more info here: https://nextjs.org/docs/messages/generate-static-params` | |
| + ) | |
| + } | |
| + | |
| + for (const [index, params] of generatedParams.entries()) { | |
| + if (!isPlainObject(params)) { | |
| + throw new Error( | |
| + `Invalid value at index ${index} returned from generateStaticParams for "${page}". Expected an object, but received type ${getValueType(params)}. See more info here: https://nextjs.org/docs/messages/generate-static-params` | |
| + ) | |
| + } | |
| + } | |
| + | |
| + return generatedParams | |
| } | |
| /** | |
| export async function generateRouteStaticParams( | |
| // Process each parent parameter combination | |
| for (const parentParams of params) { | |
| const result = await callGenerateStaticParams( | |
| + store.page, | |
| current.generateStaticParams, | |
| parentParams, | |
| rootParamKeys, | |
| export async function generateRouteStaticParams( | |
| } else { | |
| // No parent params, call generateStaticParams with empty object | |
| const result = await callGenerateStaticParams( | |
| + store.page, | |
| current.generateStaticParams, | |
| {}, | |
| rootParamKeys, | |