Next.js v15.2 creates a lot of fake scripts for server components with the same source map which breaks JS debuggers #77733
Labels
linear: next
Confirmed issue that is tracked by the Next.js team.
Link to the code that reproduces this issue
https://github.com/Soarex16/next-15-server-components-reproduction-app
To Reproduce
next dev
ornext dev --turbopack
)app/page.tsx:3
(on theconsole.log
)Current vs. Expected behavior
Expected behavior
The debugger will stop in
app/page.tsx
only once (at the breakpoint on line 3).After resuming the code, the debugger will not stop.
Actual behavior
The debugger stops at
app/page.tsx:3
, but after resume it stops at random locations in the same file.Provide environment information
Operating System: Platform: darwin Arch: arm64 Version: Darwin Kernel Version 24.3.0: Thu Jan 2 20:24:23 PST 2025; root:xnu-11215.81.4~3/RELEASE_ARM64_T6020 Available memory (MB): 65536 Available CPU cores: 12 Binaries: Node: 20.9.0 npm: 10.1.0 Yarn: 1.22.21 pnpm: 8.10.5 Relevant Packages: next: 15.3.0-canary.29 // Latest available version is detected (15.3.0-canary.29). eslint-config-next: N/A react: 19.1.0 react-dom: 19.1.0 typescript: 5.8.2 Next.js Config: output: N/A
Which area(s) are affected? (Select all that apply)
Not sure
Which stage(s) are affected? (Select all that apply)
next dev (local)
Additional context
TLDR
This confuses js debuggers because they think that this piece of code was bundled in different places multiple times.
So when the user put a breakpoint, the debugger put breakpoints in all these scripts causing redundant breaks.
Screen.Recording.2025-03-31.at.16.34.39.1.mov
Detailed investigation
I discovered this issue working on turbopack support in WebStorm.
First I thought that is another bug in our JS debugger, but after checking CDP logs
I noticed that Next.js creates a lot of scripts with url like
rsc://React/Server/webpack-internal:///(rsc)/./app/page.tsx?SOME_NUMBER
.Here is an example of one of the scripts:
All these scripts created at
react-server-dom-webpack-client.browser.development.js
.Here is one of the creation traces of such fake scripts
And since all these scripts point to the same source map, this causes JS Debuggers to set redundant breakpoints.
I made some research and that's probably caused by React Server components implementation.
Since part of a component is executed on server, React is trying to recreate stack traces for some operations in a browser. One of the examples is console.log replay:
Here, to show a correct source location in the console during replay on the client, React use these techniques with fake scripts and source maps.
The text was updated successfully, but these errors were encountered: