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

Rust React Compiler Produces Inaccurate Source Maps For Expressions Hoisted From Component Callbacks

When `turbopackRustReactCompiler` is enabled in Next.js 16.3.1, expressions hoisted or memoized from client component callbacks (e.g., inside `setTimeout`, `Promise.reject`, `console.error`) are mapped to unrelated lines/columns in production source maps, causing incorrect stack traces. Disabling the Rust compiler restores correct mappings.

highConfidence 88%Next.jsAffected V16.3.1Affected V16.3.1-Canary.18

Origin Analysis

The Rust React Compiler's code generation or transformation step does not preserve original source span information when it hoists or memoizes expressions from component callbacks. This leads to incorrect source map offsets during emission, resulting in generated positions resolving to wrong locations within the source file.
1. Clone https://github.com/istarkov/next-rust-react-compiler-sourcemap-repro and run `pnpm install`. 2. Run `pnpm repro` to build and decode the source map. 3. Observe that errors thrown in `setTimeout`, `Promise.reject`, and `console.error` inside component callbacks map to incorrect lines. 4. Alternatively, run `pnpm build && pnpm next start`, open the browser, click buttons, and inspect console stack traces. 5. Set `turbopackRustReactCompiler: false` in `next.config.js`, rebuild, and observe correct mappings.

Fixing Code Block

Edge Case Audit

This workaround disables the Rust compiler, which may significantly increase build times and reduce performance benefits. It should be treated as a temporary mitigation and reverted as soon as an official fix is released. Users relying on the Rust compiler for large builds should monitor upstream Next.js releases and apply the appropriate patch. No data is corrupted, but stack traces remain inaccurate until fixed.

Ecosystem Topology