Rust React Compiler produces inaccurate source maps for expressions hoisted from component callbacks
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 142k
- Forks
- 32.5k
- Avg merge
- 2d 14h
- Merged PRs (30d)
- 351
Description
Link to the code that reproduces this issue
https://github.com/istarkov/next-rust-react-compiler-sourcemap-repro
To Reproduce
-
Clone and install the reproduction:
git clone https://github.com/istarkov/next-rust-react-compiler-sourcemap-repro.git cd next-rust-react-compiler-sourcemap-repro pnpm install -
Build the production application and decode the emitted source map:
pnpm repro -
Observe that
directresolves to its original source line whiletimeout,rejection, andreportedresolve to unrelated lines in the same file. -
For a browser reproduction, run:
pnpm build pnpm next startOpen
http://localhost:3000, click each button, and inspect the mapped stacks in the browser console. -
Set
turbopackRustReactCompilertofalse, rebuild, and rerun the checker. The affected expressions then resolve to their correct original source lines.
The captured state update in the reproduction is important because it causes the Rust compiler to memoize and hoist the affected callback expressions. Removing that capture produces a smaller transformation that maps correctly and does not reproduce the issue.
See mappings
Current vs. Expected behavior
Production source maps should resolve errors created inside component callbacks to their correct original line and column when turbopackRustReactCompiler is enabled.
Provide environment information
Operating System:
Platform: darwin
Arch: arm64
Version: Darwin Kernel Version 25.5.0: Mon Apr 27 20:41:26 PDT 2026; root:xnu-12377.121.6~2/RELEASE_ARM64_T8132
Available memory (MB): 24576
Available CPU cores: 10
Binaries:
Node: 24.14.0
npm: 11.9.0
Yarn: 1.22.22
pnpm: 10.30.3
Relevant Packages:
next: 16.3.1 // Latest available version is detected (16.3.1).
eslint-config-next: N/A
react: 19.2.7
react-dom: 19.2.7
typescript: N/A
Next.js Config:
output: N/A
Which area(s) are affected? (Select all that apply)
Turbopack
Which stage(s) are affected? (Select all that apply)
next build (local)
Additional context
With Next.js 16.3 and the Rust React Compiler enabled:
reactCompiler: true,
experimental: {
turbopackRustReactCompiler: true,
}
some expressions hoisted from client-component callbacks have inaccurate production source mappings.
We verified this with a fresh production build by resolving the generated positions directly through the emitted source map.
Incorrect mappings were produced for:
setTimeout(() => {
throw new Error("timeout error")
}, 0)
void Promise.reject(new Error("rejection error"))
console.error(new Error("reported error"))
In each case, the source map identified the correct source file but resolved the generated expression to an unrelated line and column within that file.
Mappings remained correct for:
- a direct synchronous throw;
- an error thrown while rendering a component;
- errors created in an imported API utility module.
Disabling only turbopackRustReactCompiler while keeping reactCompiler: true made all tested positions resolve correctly. This suggests that the inaccurate mappings are introduced when the Rust compiler hoists or memoizes expressions from component callbacks.
The Rust compiler is substantially faster for our production build, so we would prefer to keep it enabled with accurate source mappings.
The issue still reproduces with:
next@16.3.1next@16.3.1-canary.18
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked next-rust-react-compiler-sourcemap-repro repository, install its dependencies, and run pnpm repro to inspect the emitted mappings under artifacts/next-16.3.1-rust. Compare the results with turbopackRustReactCompiler enabled and disabled; done means callback expressions such as timeout, rejection, and reported resolve to their original lines and columns in production source maps.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, nextjs, react, rust
- Domain
- build-system, compilers, devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100