Skip to content

Commit 378dbdf

Browse files
committed
Encode sources as "file://" protocol
This way Chrome knows where this is on disk and that it's not a relative path to the page's domain.
1 parent a44085a commit 378dbdf

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

fixtures/flight/config/webpack.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const ReactFlightWebpackPlugin = require('react-server-dom-webpack/plugin');
77
const fs = require('fs');
88
const {createHash} = require('crypto');
99
const path = require('path');
10+
const {pathToFileURL} = require('url');
1011
const webpack = require('webpack');
1112
const resolve = require('resolve');
1213
const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
@@ -235,7 +236,7 @@ module.exports = function (webpackEnv) {
235236
.relative(paths.appSrc, info.absoluteResourcePath)
236237
.replace(/\\/g, '/')
237238
: isEnvDevelopment &&
238-
(info => path.resolve(info.absoluteResourcePath).replace(/\\/g, '/')),
239+
(info => pathToFileURL(path.resolve(info.absoluteResourcePath))),
239240
},
240241
cache: {
241242
type: 'filesystem',

fixtures/flight/server/region.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// This is a server to host data-local resources like databases and RSC
44

55
const path = require('path');
6+
const url = require('url');
67

78
const register = require('react-server-dom-webpack/node-register');
89
register();
@@ -192,7 +193,7 @@ if (process.env.NODE_ENV === 'development') {
192193
// We assume that if it was prefixed with file:// it's referring to the compiled output
193194
// and if it's a direct file path we assume it's source mapped back to original format.
194195
isCompiledOutput = true;
195-
requestedFilePath = requestedFilePath.slice(7);
196+
requestedFilePath = url.fileURLToPath(requestedFilePath);
196197
}
197198

198199
const relativePath = path.relative(rootDir, requestedFilePath);
@@ -211,7 +212,9 @@ if (process.env.NODE_ENV === 'development') {
211212
// generate a source map for it so that we can add it to an ignoreList automatically.
212213
map = {
213214
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)],
215218
sourcesContent: ['// Node Internals'],
216219
mappings: 'AAAA',
217220
ignoreList: [0],
@@ -224,9 +227,11 @@ if (process.env.NODE_ENV === 'development') {
224227
// was already applied we also use this path.
225228
const sourceContent = await readFile(requestedFilePath, 'utf8');
226229
const lines = sourceContent.split('\n').length;
230+
// We ensure to absolute
231+
const sourceURL = url.pathToFileURL(requestedFilePath);
227232
map = {
228233
version: 3,
229-
sources: [requestedFilePath],
234+
sources: [sourceURL],
230235
sourcesContent: [sourceContent],
231236
// Note: This approach to mapping each line only lets you jump to each line
232237
// not jump to a column within a line. To do that, you need a proper source map

0 commit comments

Comments
 (0)