Skip to content

Commit cb49b48

Browse files
authored
Reland "Ensure mangling is disabled for dev runtime builds (#75297)" (#79201)
Reapplies #75297 Also fixes some rspack tests which didn't await assertions properly so they might have looked like they're passing
1 parent b304b45 commit cb49b48

File tree

8 files changed

+77
-237
lines changed

8 files changed

+77
-237
lines changed

contributing/core/vscode-debugger.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ To see the changes you make to the Next.js codebase during development, you can
2424

2525
When developing/debugging Next.js, you can set breakpoints anywhere in the `packages/next` source code that will stop the debugger at certain locations so you can examine the behavior. Read more about [breakpoints in the VS Code documentation](https://code.visualstudio.com/docs/nodejs/nodejs-debugging#_breakpoints).
2626

27-
To ensure that the original names are displayed in the "Variables" section, build the Next.js source code with `NEXT_SERVER_EVAL_SOURCE_MAPS=1`. This is automatically applied when using `pnpm dev`.
27+
To ensure that the original names are displayed in the "Variables" section, build the Next.js source code with `NEXT_SERVER_NO_MANGLE=1`. This is automatically applied when using `pnpm dev`.

packages/next/next-runtime.webpack-config.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
const webpack = require('@rspack/core')
22
const path = require('path')
33
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer')
4-
const EvalSourceMapDevToolPlugin = require('./webpack-plugins/eval-source-map-dev-tool-plugin')
54
const DevToolsIgnoreListPlugin = require('./webpack-plugins/devtools-ignore-list-plugin')
65

76
function shouldIgnorePath(modulePath) {
@@ -184,20 +183,21 @@ module.exports = ({ dev, turbo, bundleType, experimental, ...rest }) => {
184183
}.runtime.${dev ? 'dev' : 'prod'}.js`,
185184
libraryTarget: 'commonjs2',
186185
},
187-
devtool: process.env.NEXT_SERVER_EVAL_SOURCE_MAPS
188-
? // We'll use a fork in plugins
189-
false
190-
: 'source-map',
186+
devtool: 'source-map',
191187
optimization: {
192188
moduleIds: 'named',
193189
minimize: true,
194190
concatenateModules: true,
195-
minimizer: [new webpack.SwcJsMinimizerRspackPlugin()],
191+
minimizer: [
192+
new webpack.SwcJsMinimizerRspackPlugin({
193+
minimizerOptions: {
194+
mangle: dev || process.env.NEXT_SERVER_NO_MANGLE ? false : true,
195+
},
196+
}),
197+
],
196198
},
197199
plugins: [
198-
process.env.NEXT_SERVER_EVAL_SOURCE_MAPS
199-
? new EvalSourceMapDevToolPlugin({ shouldIgnorePath })
200-
: new DevToolsIgnoreListPlugin({ shouldIgnorePath }),
200+
new DevToolsIgnoreListPlugin({ shouldIgnorePath }),
201201
new webpack.DefinePlugin({
202202
'typeof window': JSON.stringify('undefined'),
203203
'process.env.NEXT_MINIMAL': JSON.stringify('true'),

packages/next/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
"next": "./dist/bin/next"
8181
},
8282
"scripts": {
83-
"dev": "cross-env NEXT_SERVER_EVAL_SOURCE_MAPS=1 taskr",
83+
"dev": "cross-env NEXT_SERVER_NO_MANGLE=1 taskr",
8484
"release": "taskr release",
8585
"build": "pnpm release",
8686
"prepublishOnly": "cd ../../ && turbo run build",

packages/next/src/build/webpack/plugins/eval-source-map-dev-tool-plugin.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
Author Tobias Koppers @sokra
44
55
Forked to add support for `ignoreList`.
6-
Keep in sync with packages/next/webpack-plugins/eval-source-map-dev-tool-plugin.js
76
*/
87
import {
98
type webpack,

packages/next/webpack-plugins/eval-source-map-dev-tool-plugin.js

Lines changed: 0 additions & 219 deletions
This file was deleted.

test/development/app-dir/ssr-in-rsc/ssr-in-rsc.test.ts

Lines changed: 61 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ import {
88
} from 'next-test-utils'
99

1010
const isReactExperimental = process.env.__NEXT_EXPERIMENTAL_PPR === 'true'
11-
1211
const isReact18 = parseInt(process.env.NEXT_TEST_REACT_VERSION) === 18
1312

13+
const isRspack = process.env.NEXT_RSPACK !== undefined
14+
1415
describe('react-dom/server in React Server environment', () => {
1516
const dependencies = (global as any).isNextDeploy
1617
? // `link` is incompatible with the npm version used when this test is deployed
@@ -266,7 +267,7 @@ describe('react-dom/server in React Server environment', () => {
266267
)
267268

268269
if (isTurbopack) {
269-
expect(browser).toDisplayRedbox(`
270+
await expect(browser).toDisplayRedbox(`
270271
{
271272
"description": "Ecmascript file had an error",
272273
"environmentLabel": null,
@@ -278,11 +279,41 @@ describe('react-dom/server in React Server environment', () => {
278279
"stack": [],
279280
}
280281
`)
282+
} else if (isRspack) {
283+
await expect(browser).toDisplayRedbox(`
284+
{
285+
"description": " × Module build failed:",
286+
"environmentLabel": null,
287+
"label": "Build Error",
288+
"source": "<FIXME-nextjs-internal-source>
289+
× Module build failed:
290+
╰─▶ × Error: x You're importing a component that imports react-dom/server. To fix it, render or return the content directly as a Server Component instead for perf and security.
291+
│ | Learn more: https://nextjs.org/docs/app/building-your-application/rendering
292+
│ ,-[1:1]
293+
│ 1 | import * as ReactDOMServerEdge from 'react-dom/server'
294+
│ : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
295+
│ 2 | // Fine to drop once React is on ESM
296+
│ 3 | import ReactDOMServerEdgeDefault from 'react-dom/server'
297+
│ \`----
298+
│ x You're importing a component that imports react-dom/server. To fix it, render or return the content directly as a Server Component instead for perf and security.
299+
│ | Learn more: https://nextjs.org/docs/app/building-your-application/rendering
300+
│ ,-[3:1]
301+
│ 1 | import * as ReactDOMServerEdge from 'react-dom/server'
302+
│ 2 | // Fine to drop once React is on ESM
303+
│ 3 | import ReactDOMServerEdgeDefault from 'react-dom/server'
304+
│ : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
305+
│ 4 |
306+
│ 5 | export const runtime = 'edge'
307+
│ \`----
308+
│",
309+
"stack": [],
310+
}
311+
`)
281312
} else {
282313
// FIXME: the source map of source file path is not correct
283314
// Expected: `./app/exports/app-code/react-dom-server-edge-implicit/page.js`
284315
// Observed: `./node_modules/.pnpm/next@file+..+next-repo.../page.js?__next_edge_ssr_entry__
285-
expect(browser).toDisplayRedbox(`
316+
await expect(browser).toDisplayRedbox(`
286317
{
287318
"description": " x You're importing a component that imports react-dom/server. To fix it, render or return the content directly as a Server Component instead for perf and security.",
288319
"environmentLabel": null,
@@ -397,6 +428,33 @@ describe('react-dom/server in React Server environment', () => {
397428
Learn more: https://nextjs.org/docs/app/building-your-application/rendering",
398429
}
399430
`)
431+
} else if (isRspack) {
432+
expect(redbox).toMatchInlineSnapshot(`
433+
{
434+
"description": " × Module build failed:",
435+
"source": "./app/exports/app-code/react-dom-server-node-implicit/page.js
436+
× Module build failed:
437+
╰─▶ × Error: x You're importing a component that imports react-dom/server. To fix it, render or return the content directly as a Server Component instead for perf and security.
438+
│ | Learn more: https://nextjs.org/docs/app/building-your-application/rendering
439+
│ ,-[1:1]
440+
│ 1 | import * as ReactDOMServerNode from 'react-dom/server'
441+
│ : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
442+
│ 2 | // Fine to drop once React is on ESM
443+
│ 3 | import ReactDOMServerNodeDefault from 'react-dom/server'
444+
│ \`----
445+
│ x You're importing a component that imports react-dom/server. To fix it, render or return the content directly as a Server Component instead for perf and security.
446+
│ | Learn more: https://nextjs.org/docs/app/building-your-application/rendering
447+
│ ,-[3:1]
448+
│ 1 | import * as ReactDOMServerNode from 'react-dom/server'
449+
│ 2 | // Fine to drop once React is on ESM
450+
│ 3 | import ReactDOMServerNodeDefault from 'react-dom/server'
451+
│ : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
452+
│ 4 |
453+
│ 5 | export const runtime = 'nodejs'
454+
│ \`----
455+
│",
456+
}
457+
`)
400458
} else {
401459
expect(redbox).toMatchInlineSnapshot(`
402460
{

test/e2e/app-dir/use-cache-segment-configs/use-cache-segment-configs.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ describe('use-cache-segment-configs', () => {
2020
await assertHasRedbox(browser)
2121

2222
if (isTurbopack) {
23-
expect(browser).toDisplayRedbox(`
23+
await expect(browser).toDisplayRedbox(`
2424
{
2525
"description": "Ecmascript file had an error",
2626
"environmentLabel": null,
@@ -34,7 +34,7 @@ describe('use-cache-segment-configs', () => {
3434
`)
3535
} else {
3636
// FIXME: Fix broken import trace for Webpack loader resource.
37-
expect(browser).toDisplayRedbox(`
37+
await expect(browser).toDisplayRedbox(`
3838
{
3939
"description": " x Route segment config "runtime" is not compatible with \`nextConfig.experimental.useCache\`. Please remove it.",
4040
"environmentLabel": null,

0 commit comments

Comments
 (0)