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

GenerateStaticParams With Output=Export Is Flaky In Dev Env With Encoded Params

In Next.js dev mode with output: export, dynamic routes with parameters requiring URL encoding (e.g., spaces) intermittently fail with a missing param error, while production builds work correctly. The bug depends on navigation order and is caused by inconsistent handling of encoded vs. decoded parameters.

highConfidence 70%Next.jsAffected V16.4.0-Canary.19

Origin Analysis

Next.js dev server compares encoded URL parameters (e.g., 'with%20space') directly against the unencoded parameter list returned by generateStaticParams (e.g., 'with space'), causing a false mismatch. The flakiness arises from dev-mode route cache updates that sometimes retain previously matched parameters.
1. Create a Next.js app with output: export and a dynamic route /[url]/page.js using generateStaticParams returning ['with space', 'nospace']. 2. Run `next dev` and open localhost:3000. 3. Click a link to /with space → observe error: Page "/[url]/page" is missing param "/[url]" in "generateStaticParams()". 4. Navigate to /nospace first, then to /with space → no error. 5. Navigate back home and then to /with space again → error reappears. 6. Run `next build` → builds successfully without errors.

Fixing Code Block

Edge Case Audit

This is a temporary patch to node_modules and will be lost on upgrade. It may mis-handle parameters that legitimately contain percent signs or other encoded characters. Test thoroughly with mixed parameters. A safer workaround for users is to avoid output: export in dev or use parameters without special characters until the upstream fix is released. Rollback: restore the original node_modules file or reinstall Next.js.

Ecosystem Topology