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

Dev Server Crash In Next-Code-Frame When Truncating Multi-Byte UTF-8 To Terminal Display Width

The Next.js dev error overlay's Rust-based code frame panics with a byte-index boundary error when a source line contains multi-byte characters and is truncated based on terminal display columns. The crash aborts the dev server and is dependent on terminal width.

highConfidence 88%Next.jsPages RouterHydrationApp RouterAffected V16.2.1-Canary.20

Origin Analysis

In crates/next-code-frame/src/highlight.rs extract_highlights(), available_code_width is a display-column width but is used directly as a byte length for substring slicing, causing the slice end to fall inside a multi-byte UTF-8 character and triggering Rust's char boundary panic.
1. Create a Next.js app with a runtime error and a long JSX line containing Japanese text in a title attribute. 2. Start the dev server with npm run dev. 3. Open the page to trigger the error overlay. 4. If no crash occurs, resize the terminal running npm run dev to vary display width and reload the page. Repeat until the panic appears.

Fixing Code Block

Edge Case Audit

This fix changes the code frame truncation to be display-width accurate; lines with many narrow or zero-width characters may be truncated slightly earlier than before, which is intended. Ensure the unicode-width crate is already a dependency (it is commonly used for terminal width); otherwise add it to Cargo.toml. The fix is localized to the Rust code and has no concurrency or multi-threading implications because the function is pure and stateless. Rollback is possible by reverting to the previous byte-length slicing, but that will restore the panic. No version-specific API changes are expected.

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