3
3
// This is a server to host data-local resources like databases and RSC
4
4
5
5
const path = require ( 'path' ) ;
6
+ const url = require ( 'url' ) ;
6
7
7
8
const register = require ( 'react-server-dom-webpack/node-register' ) ;
8
9
register ( ) ;
@@ -192,7 +193,7 @@ if (process.env.NODE_ENV === 'development') {
192
193
// We assume that if it was prefixed with file:// it's referring to the compiled output
193
194
// and if it's a direct file path we assume it's source mapped back to original format.
194
195
isCompiledOutput = true ;
195
- requestedFilePath = requestedFilePath . slice ( 7 ) ;
196
+ requestedFilePath = url . fileURLToPath ( requestedFilePath ) ;
196
197
}
197
198
198
199
const relativePath = path . relative ( rootDir , requestedFilePath ) ;
@@ -211,7 +212,9 @@ if (process.env.NODE_ENV === 'development') {
211
212
// generate a source map for it so that we can add it to an ignoreList automatically.
212
213
map = {
213
214
version : 3 ,
214
- sources : [ requestedFilePath ] ,
215
+ // We use the node:// protocol convention to teach Chrome DevTools that this is
216
+ // on a different protocol and not part of the current page.
217
+ sources : [ 'node:///' + requestedFilePath . slice ( 5 ) ] ,
215
218
sourcesContent : [ '// Node Internals' ] ,
216
219
mappings : 'AAAA' ,
217
220
ignoreList : [ 0 ] ,
@@ -224,9 +227,11 @@ if (process.env.NODE_ENV === 'development') {
224
227
// was already applied we also use this path.
225
228
const sourceContent = await readFile ( requestedFilePath , 'utf8' ) ;
226
229
const lines = sourceContent . split ( '\n' ) . length ;
230
+ // We ensure to absolute
231
+ const sourceURL = url . pathToFileURL ( requestedFilePath ) ;
227
232
map = {
228
233
version : 3 ,
229
- sources : [ requestedFilePath ] ,
234
+ sources : [ sourceURL ] ,
230
235
sourcesContent : [ sourceContent ] ,
231
236
// Note: This approach to mapping each line only lets you jump to each line
232
237
// not jump to a column within a line. To do that, you need a proper source map
0 commit comments