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

Next.Js 16 Regression: Non-Latin-1 Route Group/Segment Names Crash With InvalidCharacterError Due To Btoa In Segment-Value-Encoding

In Next.js 16, route groups or segments with non-ASCII names (e.g. (안녕), (日本), (café), emoji) cause dev server 500, build failure, and prerender error because encodeToFilesystemAndURLSafeString calls btoa directly on the raw Unicode string, which only accepts Latin-1 characters. The segment cache is enabled by default in Next 16, so every such segment hits this path. A UTF-8 safe encoding is required.

highConfidence 95%Next.jsApp RouterHydrationnext buildAffected V16.3.3

Origin Analysis

encodeToFilesystemAndURLSafeString in packages/next/src/shared/lib/segment-cache/segment-value-encoding.ts uses btoa(value) without first converting the string to a UTF-8 byte sequence. btoa only supports characters in the Latin-1 range (0-255), so any non-Latin-1 character (CJK, Cyrillic, emoji, accented Latin-1 supplement) throws DOMException: InvalidCharacterError. This function is used for the segment cache key which is now always enabled in Next 16, causing build/prerender and dev server crashes for affected routes.
1. npx create-next-app@latest repro --app --ts --no-tailwind --no-eslint 2. Create route group with non-ASCII name and page: app/(안녕)/hello/page.tsx 3. Run next dev and open /hello -> observe 500 and InvalidCharacterError in terminal 4. Run next build -> observe prerender failure and export error

Fixing Code Block

Edge Case Audit

This changes the encoded representation for non-ASCII segment names. If any cached segment cache entries (.next/cache) were generated with the old encoding (though they would have crashed, so unlikely), they may need invalidation. After applying the fix, delete the .next directory to avoid stale key mismatches. Ensure the corresponding decode function (if any) also uses TextDecoder or equivalent to convert the binary string back to UTF-8 bytes to maintain round-trip consistency. For rollback, restore the original btoa(value) call but note that non-ASCII segment names will again crash. No cross-platform issues expected since TextEncoder is globally available in Node.js (>=11) and all modern browsers.

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