vercel / vercel/next.js

Rust React Compiler produces inaccurate source maps for expressions hoisted from component callbacks

Open
#97,392 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

SWC Turbopack
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
  1. 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
    
  2. Build the production application and decode the emitted source map:

    pnpm repro
    
  3. Observe that direct resolves to its original source line while timeout, rejection, and reported resolve to unrelated lines in the same file.

  4. For a browser reproduction, run:

    pnpm build
    pnpm next start
    

    Open http://localhost:3000, click each button, and inspect the mapped stacks in the browser console.

  5. Set turbopackRustReactCompiler to false, 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

https://github.com/istarkov/next-rust-react-compiler-sourcemap-repro/tree/main/artifacts/next-16.3.1-rust

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.1
  • next@16.3.1-canary.18

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.