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

Next.Js 16.2.1 I18n Prefix Incorrectly Applied To API Routes When Proxy.Ts Matcher Includes /Api/Trpc

On Vercel deployments with i18n (defaultLocale pt-BR) and a proxy.ts matcher that includes /api/trpc, all API requests return 404 because the locale prefix is prepended to the API path and the static i18n 404 page is served from the Full Route Cache.

highConfidence 72%Next.jsnext buildRoute HandlersApp RouterAffected V16.2.1

Origin Analysis

Next.js 16.2.1's internal i18n routing incorrectly applies the default locale prefix to /api/* paths when a custom proxy.ts matcher includes those API routes, causing the request to be rewritten to /<locale>/api/... and miss the actual API route handler.
1. Create a Next.js 16.2.1 app with i18n config using defaultLocale 'pt-BR'. 2. Add a proxy.ts file with a matcher that includes api/trpc routes (e.g. '/(api|trpc)(.*)'). 3. Define a pages/api/trpc/[trpc].ts route. 4. Deploy to Vercel and request /api/trpc/<procedure>. 5. Observe 404 Not Found and Vercel log showing internal path /pt-BR/api/trpc/<procedure> with Cache key /pt-BR/404.

Fixing Code Block

Edge Case Audit

This workaround removes proxy-based middleware from API routes; ensure all required API middleware (e.g., auth, rate limiting) is re-implemented in each API handler. Test thoroughly in local and Vercel preview. If you later upgrade Next.js to a version where this bug is fixed, you can revert to the original matcher. Rollback by restoring the previous proxy.ts matcher and removing the manual auth from API handlers.

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