Skip to content

Commit 6a9f9bc

Browse files
committed
Generate source map for server actions in ESM loader
We use the webpack-sources dependency as a utility but it doesn't use anything from webpack and it's a small dep. Could maybe inline into build.
1 parent 7fe6896 commit 6a9f9bc

File tree

5 files changed

+373
-58
lines changed

5 files changed

+373
-58
lines changed

fixtures/flight-esm/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@
1313
"prompts": "^2.4.2",
1414
"react": "experimental",
1515
"react-dom": "experimental",
16-
"undici": "^5.20.0"
16+
"undici": "^5.20.0",
17+
"webpack-sources": "^3.2.0"
1718
},
1819
"scripts": {
1920
"predev": "cp -r ../../build/oss-experimental/* ./node_modules/",
2021
"prestart": "cp -r ../../build/oss-experimental/* ./node_modules/",
2122
"dev": "concurrently \"npm run dev:region\" \"npm run dev:global\"",
2223
"dev:global": "NODE_ENV=development BUILD_PATH=dist node server/global",
23-
"dev:region": "NODE_ENV=development BUILD_PATH=dist nodemon --watch src --watch dist -- --experimental-loader ./loader/region.js --conditions=react-server server/region",
24+
"dev:region": "NODE_ENV=development BUILD_PATH=dist nodemon --watch src --watch dist -- --enable-source-maps --experimental-loader ./loader/region.js --conditions=react-server server/region",
2425
"start": "concurrently \"npm run start:region\" \"npm run start:global\"",
2526
"start:global": "NODE_ENV=production node server/global",
2627
"start:region": "NODE_ENV=production node --experimental-loader ./loader/region.js --conditions=react-server server/region"

fixtures/flight-esm/server/region.js

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,7 @@ if (process.env.NODE_ENV === 'development') {
141141

142142
const sourceMap = nodeModule.findSourceMap(requestedFilePath);
143143
let map;
144-
// There are two ways to return a source map depending on what we observe in error.stack.
145-
// A real app will have a similar choice to make for which strategy to pick.
146-
if (!sourceMap || Error.prepareStackTrace === undefined) {
147-
// When --enable-source-maps is enabled, the error.stack that we use to track
148-
// stacks will have had the source map already applied so it's pointing to the
149-
// original source. We return a blank source map that just maps everything to
150-
// the original source in this case.
144+
if (!sourceMap) {
151145
const sourceContent = await readFile(requestedFilePath, 'utf8');
152146
const lines = sourceContent.split('\n').length;
153147
map = {
@@ -161,13 +155,6 @@ if (process.env.NODE_ENV === 'development') {
161155
sourceRoot: '',
162156
};
163157
} else {
164-
// If something has overridden prepareStackTrace it is likely not getting the
165-
// natively applied source mapping to error.stack and so the line will point to
166-
// the compiled output similar to how a browser works.
167-
// E.g. ironically this can happen with the source-map-support library that is
168-
// auto-invoked by @babel/register if external source maps are generated.
169-
// In this case we just use the source map that the native source mapping would
170-
// have used.
171158
map = sourceMap.payload;
172159
}
173160
res.write(JSON.stringify(map));

fixtures/flight-esm/yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,11 @@ vary@~1.1.2:
755755
resolved "https://registry.yarnpkg.com/vary/-/vary-1.1.2.tgz#2299f02c6ded30d4a5961b0b9f74524a18f634fc"
756756
integrity sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==
757757

758+
webpack-sources@^3.2.0:
759+
version "3.2.3"
760+
resolved "https://registry.yarnpkg.com/webpack-sources/-/webpack-sources-3.2.3.tgz#2d4daab8451fd4b240cc27055ff6a0c2ccea0cde"
761+
integrity sha512-/DyMEOrDgLKKIG0fmvtz+4dUX/3Ghozwgm6iPp8KRhvn+eQf9+Q7GWxVNMk3+uCPWfdXYC4ExGBckIXdFEfH1w==
762+
758763
wrap-ansi@^7.0.0:
759764
version "7.0.0"
760765
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"

packages/react-server-dom-esm/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
"react-dom": "^19.0.0"
5959
},
6060
"dependencies": {
61-
"acorn-loose": "^8.3.0"
61+
"acorn-loose": "^8.3.0",
62+
"webpack-sources": "^3.2.0"
6263
}
6364
}

0 commit comments

Comments
 (0)