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

Next/Root-Params Typegen Silently Produces `Any` When Two Sibling Root Layouts Exist And One Serves "/"

Next.js 16.3.x type generation for `next/root-params` fails when an app has multiple root layouts, one of which is normalized to `/`. The generated `.next/types/root-params.d.ts` contains only `export {}` and the shipped ambient declaration resolves the module to `any`, silently bypassing strict TypeScript checks.

highConfidence 87%Next.jsReact Server ComponentsApp RouterAffected V16.3.0Affected V16.3.1-Canary.3

Origin Analysis

In `collectRootParamsFromLayouts` (packages/next/src/server/lib/router-utils/route-types-utils.ts), root layout detection uses normalized route strings after route groups are stripped. The condition `other === '/'` treats the root `/` route as an ancestor of every route, causing the sibling root layout `app/[locale]/layout.tsx` (normalized to `/[locale]`) to be filtered out. Because route group information is lost before comparison, the code cannot distinguish sibling root layouts from true ancestors.
1. Create two sibling root layouts: `app/(marketing)/layout.tsx` serving `/` and `app/[locale]/layout.tsx` serving `/[locale]/*`. 2. Run `npx next typegen`. 3. Inspect `.next/types/root-params.d.ts`; it contains `// No root params detected.` and `export {}`. 4. Temporarily move `app/(marketing)` away and rerun `npx next typegen`; the `locale` function appears correctly. 5. Restore `app/(marketing)` and observe the type disappears again.

Fixing Code Block

Edge Case Audit

This fix relies on `filePath` being present and accurate for all layout routes. Routes without `filePath` fall back to `false`, which could cause some nested layouts to be mistakenly treated as root layouts in rare internal call sites. It assumes POSIX-style path separators; Windows paths are normalized via `path.posix`. Projects with deeply nested route groups (`app/(a)/(b)/layout.tsx`) should be tested to confirm the root layout is still detected. Rollback safely by restoring the original string-based predicate if unexpected typegen regressions appear.

Ecosystem Topology

Agent Frameworks

LangChain, LlamaIndex, and Pydantic

  1. highProperty graph relation keys collide when entity IDs or labels contain underscores
  2. highCodeActAgent drops assistant tool-call metadata during handoff, leaving an orphan tool response
  3. high[Bug]: HierarchicalNodeParser async methods return the documents unsplit
  4. highLLM.predict_and_call fails with ValidationError for non-function-calling models when react_chat_formatter is omitted
  5. highAnthropic streaming server-tool input_json_delta overwrites completed client tool_use arguments due to stale cur_tool_call state