Skip to content

Commit

Permalink
Don't minify symbols in production builds (#28881)
Browse files Browse the repository at this point in the history
This disables symbol renaming in production builds. The original
variable and function names are preserved. All other forms of
compression applied by Closure (dead code elimination, inlining, etc)
are unchanged — the final program is identical to what we were producing
before, just in a more readable form.

The motivation is to make it easier to debug React issues that only
occur in production — the same reason we decided to start shipping
sourcemaps in #28827 and #28827.

However, because most apps run their own minification step on their npm
dependencies, it's not necessary for us to minify the symbols before
publishing — it'll be handled the app, if desired.

This is the same strategy Meta has used to ship React for years. The
React build itself has unminified symbols, but they get minified as part
of Meta's regular build pipeline.

Even if an app does not minify their npm dependencies, gzip covers most
of the cost of symbol renaming anyway.

This saves us from having to ship sourcemaps, which means even apps that
don't have sourcemaps configured will be able to debug the React build
as easily as they would any other npm dependency.
  • Loading branch information
acdlite authored Apr 20, 2024
1 parent ea26e38 commit 857ee8c
Show file tree
Hide file tree
Showing 83 changed files with 101 additions and 259 deletions.
4 changes: 2 additions & 2 deletions dangerfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ const SIGNIFICANCE_THRESHOLD = 0.002;
const CRITICAL_ARTIFACT_PATHS = new Set([
// We always report changes to these bundles, even if the change is
// insignificant or non-existent.
'oss-stable/react-dom/cjs/react-dom.production.min.js',
'oss-experimental/react-dom/cjs/react-dom.production.min.js',
'oss-stable/react-dom/cjs/react-dom.production.js',
'oss-experimental/react-dom/cjs/react-dom.production.js',
'facebook-www/ReactDOM-prod.classic.js',
'facebook-www/ReactDOM-prod.modern.js',
]);
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@
"shelljs": "^0.8.5",
"signedsource": "^2.0.0",
"targz": "^1.0.1",
"terser": "^5.30.3",
"through2": "^3.0.1",
"tmp": "^0.1.0",
"typescript": "^3.7.5",
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin-react-hooks/npm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// TODO: this doesn't make sense for an ESLint rule.
// We need to fix our build process to not create bundles for "raw" packages like this.
if (process.env.NODE_ENV === 'production') {
module.exports = require('./cjs/eslint-plugin-react-hooks.production.min.js');
module.exports = require('./cjs/eslint-plugin-react-hooks.production.js');
} else {
module.exports = require('./cjs/eslint-plugin-react-hooks.development.js');
}
2 changes: 1 addition & 1 deletion packages/jest-react/npm/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

if (process.env.NODE_ENV === 'production') {
module.exports = require('./cjs/jest-react.production.min.js');
module.exports = require('./cjs/jest-react.production.js');
} else {
module.exports = require('./cjs/jest-react.development.js');
}
2 changes: 1 addition & 1 deletion packages/react-art/npm/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

if (process.env.NODE_ENV === 'production') {
module.exports = require('./cjs/react-art.production.min.js');
module.exports = require('./cjs/react-art.production.js');
} else {
module.exports = require('./cjs/react-art.development.js');
}
2 changes: 1 addition & 1 deletion packages/react-cache/npm/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

if (process.env.NODE_ENV === 'production') {
module.exports = require('./cjs/react-cache.production.min.js');
module.exports = require('./cjs/react-cache.production.js');
} else {
module.exports = require('./cjs/react-cache.development.js');
}
2 changes: 1 addition & 1 deletion packages/react-client/npm/flight.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

if (process.env.NODE_ENV === 'production') {
module.exports = require('./cjs/react-client-flight.production.min.js');
module.exports = require('./cjs/react-client-flight.production.js');
} else {
module.exports = require('./cjs/react-client-flight.development.js');
}
2 changes: 1 addition & 1 deletion packages/react-debug-tools/npm/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

if (process.env.NODE_ENV === 'production') {
module.exports = require('./cjs/react-debug-tools.production.min.js');
module.exports = require('./cjs/react-debug-tools.production.js');
} else {
module.exports = require('./cjs/react-debug-tools.development.js');
}
2 changes: 1 addition & 1 deletion packages/react-dom/npm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ if (process.env.NODE_ENV === 'production') {
// DCE check should happen before ReactDOM bundle executes so that
// DevTools can report bad minification during injection.
checkDCE();
module.exports = require('./cjs/react-dom.production.min.js');
module.exports = require('./cjs/react-dom.production.js');
} else {
module.exports = require('./cjs/react-dom.development.js');
}
2 changes: 1 addition & 1 deletion packages/react-dom/npm/profiling.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ if (process.env.NODE_ENV === 'production') {
// DCE check should happen before ReactDOM bundle executes so that
// DevTools can report bad minification during injection.
checkDCE();
module.exports = require('./cjs/react-dom.profiling.min.js');
module.exports = require('./cjs/react-dom.profiling.js');
} else {
module.exports = require('./cjs/react-dom.development.js');
}
2 changes: 1 addition & 1 deletion packages/react-dom/npm/react-dom.react-server.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

if (process.env.NODE_ENV === 'production') {
module.exports = require('./cjs/react-dom.react-server.production.min.js');
module.exports = require('./cjs/react-dom.react-server.production.js');
} else {
module.exports = require('./cjs/react-dom.react-server.development.js');
}
2 changes: 1 addition & 1 deletion packages/react-dom/npm/server-rendering-stub.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

if (process.env.NODE_ENV === 'production') {
module.exports = require('./cjs/react-dom-server-rendering-stub.production.min.js');
module.exports = require('./cjs/react-dom-server-rendering-stub.production.js');
} else {
module.exports = require('./cjs/react-dom-server-rendering-stub.development.js');
}
4 changes: 2 additions & 2 deletions packages/react-dom/npm/server.browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

var l, s;
if (process.env.NODE_ENV === 'production') {
l = require('./cjs/react-dom-server-legacy.browser.production.min.js');
s = require('./cjs/react-dom-server.browser.production.min.js');
l = require('./cjs/react-dom-server-legacy.browser.production.js');
s = require('./cjs/react-dom-server.browser.production.js');
} else {
l = require('./cjs/react-dom-server-legacy.browser.development.js');
s = require('./cjs/react-dom-server.browser.development.js');
Expand Down
4 changes: 2 additions & 2 deletions packages/react-dom/npm/server.bun.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
var b;
var l;
if (process.env.NODE_ENV === 'production') {
b = require('./cjs/react-dom-server.bun.production.min.js');
l = require('./cjs/react-dom-server-legacy.browser.production.min.js');
b = require('./cjs/react-dom-server.bun.production.js');
l = require('./cjs/react-dom-server-legacy.browser.production.js');
} else {
b = require('./cjs/react-dom-server.bun.development.js');
l = require('./cjs/react-dom-server-legacy.browser.development.js');
Expand Down
4 changes: 2 additions & 2 deletions packages/react-dom/npm/server.edge.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
var b;
var l;
if (process.env.NODE_ENV === 'production') {
b = require('./cjs/react-dom-server.edge.production.min.js');
l = require('./cjs/react-dom-server-legacy.browser.production.min.js');
b = require('./cjs/react-dom-server.edge.production.js');
l = require('./cjs/react-dom-server-legacy.browser.production.js');
} else {
b = require('./cjs/react-dom-server.edge.development.js');
l = require('./cjs/react-dom-server-legacy.browser.development.js');
Expand Down
4 changes: 2 additions & 2 deletions packages/react-dom/npm/server.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

var l, s;
if (process.env.NODE_ENV === 'production') {
l = require('./cjs/react-dom-server-legacy.node.production.min.js');
s = require('./cjs/react-dom-server.node.production.min.js');
l = require('./cjs/react-dom-server-legacy.node.production.js');
s = require('./cjs/react-dom-server.node.production.js');
} else {
l = require('./cjs/react-dom-server-legacy.node.development.js');
s = require('./cjs/react-dom-server.node.development.js');
Expand Down
2 changes: 1 addition & 1 deletion packages/react-dom/npm/static.browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

var s;
if (process.env.NODE_ENV === 'production') {
s = require('./cjs/react-dom-server.browser.production.min.js');
s = require('./cjs/react-dom-server.browser.production.js');
} else {
s = require('./cjs/react-dom-server.browser.development.js');
}
Expand Down
2 changes: 1 addition & 1 deletion packages/react-dom/npm/static.edge.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

var s;
if (process.env.NODE_ENV === 'production') {
s = require('./cjs/react-dom-server.edge.production.min.js');
s = require('./cjs/react-dom-server.edge.production.js');
} else {
s = require('./cjs/react-dom-server.edge.development.js');
}
Expand Down
2 changes: 1 addition & 1 deletion packages/react-dom/npm/static.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

var s;
if (process.env.NODE_ENV === 'production') {
s = require('./cjs/react-dom-server.node.production.min.js');
s = require('./cjs/react-dom-server.node.production.js');
} else {
s = require('./cjs/react-dom-server.node.development.js');
}
Expand Down
2 changes: 1 addition & 1 deletion packages/react-dom/npm/test-utils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

if (process.env.NODE_ENV === 'production') {
module.exports = require('./cjs/react-dom-test-utils.production.min.js');
module.exports = require('./cjs/react-dom-test-utils.production.js');
} else {
module.exports = require('./cjs/react-dom-test-utils.development.js');
}
2 changes: 1 addition & 1 deletion packages/react-dom/npm/unstable_testing.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ if (process.env.NODE_ENV === 'production') {
// DCE check should happen before ReactDOM bundle executes so that
// DevTools can report bad minification during injection.
checkDCE();
module.exports = require('./cjs/react-dom-unstable_testing.production.min.js');
module.exports = require('./cjs/react-dom-unstable_testing.production.js');
} else {
module.exports = require('./cjs/react-dom-unstable_testing.development.js');
}
2 changes: 1 addition & 1 deletion packages/react-is/npm/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

if (process.env.NODE_ENV === 'production') {
module.exports = require('./cjs/react-is.production.min.js');
module.exports = require('./cjs/react-is.production.js');
} else {
module.exports = require('./cjs/react-is.development.js');
}
2 changes: 1 addition & 1 deletion packages/react-noop-renderer/npm/flight-client.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

if (process.env.NODE_ENV === 'production') {
module.exports = require('./cjs/react-noop-renderer-flight-client.production.min.js');
module.exports = require('./cjs/react-noop-renderer-flight-client.production.js');
} else {
module.exports = require('./cjs/react-noop-renderer-flight-client.development.js');
}
2 changes: 1 addition & 1 deletion packages/react-noop-renderer/npm/flight-server.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

if (process.env.NODE_ENV === 'production') {
module.exports = require('./cjs/react-noop-renderer-flight-server.production.min.js');
module.exports = require('./cjs/react-noop-renderer-flight-server.production.js');
} else {
module.exports = require('./cjs/react-noop-renderer-flight-server.development.js');
}
2 changes: 1 addition & 1 deletion packages/react-noop-renderer/npm/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

if (process.env.NODE_ENV === 'production') {
module.exports = require('./cjs/react-noop-renderer.production.min.js');
module.exports = require('./cjs/react-noop-renderer.production.js');
} else {
module.exports = require('./cjs/react-noop-renderer.development.js');
}
2 changes: 1 addition & 1 deletion packages/react-noop-renderer/npm/persistent.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

if (process.env.NODE_ENV === 'production') {
module.exports = require('./cjs/react-noop-renderer-persistent.production.min.js');
module.exports = require('./cjs/react-noop-renderer-persistent.production.js');
} else {
module.exports = require('./cjs/react-noop-renderer-persistent.development.js');
}
2 changes: 1 addition & 1 deletion packages/react-noop-renderer/npm/server.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

if (process.env.NODE_ENV === 'production') {
module.exports = require('./cjs/react-noop-renderer-server.production.min.js');
module.exports = require('./cjs/react-noop-renderer-server.production.js');
} else {
module.exports = require('./cjs/react-noop-renderer-server.development.js');
}
2 changes: 1 addition & 1 deletion packages/react-reconciler/npm/constants.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

if (process.env.NODE_ENV === 'production') {
module.exports = require('./cjs/react-reconciler-constants.production.min.js');
module.exports = require('./cjs/react-reconciler-constants.production.js');
} else {
module.exports = require('./cjs/react-reconciler-constants.development.js');
}
2 changes: 1 addition & 1 deletion packages/react-reconciler/npm/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

if (process.env.NODE_ENV === 'production') {
module.exports = require('./cjs/react-reconciler.production.min.js');
module.exports = require('./cjs/react-reconciler.production.js');
} else {
module.exports = require('./cjs/react-reconciler.development.js');
}
2 changes: 1 addition & 1 deletion packages/react-reconciler/npm/reflection.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

if (process.env.NODE_ENV === 'production') {
module.exports = require('./cjs/react-reconciler-reflection.production.min.js');
module.exports = require('./cjs/react-reconciler-reflection.production.js');
} else {
module.exports = require('./cjs/react-reconciler-reflection.development.js');
}
2 changes: 1 addition & 1 deletion packages/react-refresh/npm/babel.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

if (process.env.NODE_ENV === 'production') {
module.exports = require('./cjs/react-refresh-babel.production.min.js');
module.exports = require('./cjs/react-refresh-babel.production.js');
} else {
module.exports = require('./cjs/react-refresh-babel.development.js');
}
2 changes: 1 addition & 1 deletion packages/react-refresh/npm/runtime.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

if (process.env.NODE_ENV === 'production') {
module.exports = require('./cjs/react-refresh-runtime.production.min.js');
module.exports = require('./cjs/react-refresh-runtime.production.js');
} else {
module.exports = require('./cjs/react-refresh-runtime.development.js');
}
2 changes: 1 addition & 1 deletion packages/react-server-dom-esm/npm/client.browser.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

if (process.env.NODE_ENV === 'production') {
module.exports = require('./cjs/react-server-dom-esm-client.browser.production.min.js');
module.exports = require('./cjs/react-server-dom-esm-client.browser.production.js');
} else {
module.exports = require('./cjs/react-server-dom-esm-client.browser.development.js');
}
2 changes: 1 addition & 1 deletion packages/react-server-dom-esm/npm/client.node.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

if (process.env.NODE_ENV === 'production') {
module.exports = require('./cjs/react-server-dom-esm-client.node.production.min.js');
module.exports = require('./cjs/react-server-dom-esm-client.node.production.js');
} else {
module.exports = require('./cjs/react-server-dom-esm-client.node.development.js');
}
2 changes: 1 addition & 1 deletion packages/react-server-dom-esm/npm/server.node.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

if (process.env.NODE_ENV === 'production') {
module.exports = require('./cjs/react-server-dom-esm-server.node.production.min.js');
module.exports = require('./cjs/react-server-dom-esm-server.node.production.js');
} else {
module.exports = require('./cjs/react-server-dom-esm-server.node.development.js');
}
2 changes: 1 addition & 1 deletion packages/react-server-dom-esm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"default": "./server.js"
},
"./server.node": "./server.node.js",
"./node-loader": "./esm/react-server-dom-esm-node-loader.production.min.js",
"./node-loader": "./esm/react-server-dom-esm-node-loader.production.js",
"./src/*": "./src/*.js",
"./package.json": "./package.json"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/react-server-dom-turbopack/npm/client.browser.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

if (process.env.NODE_ENV === 'production') {
module.exports = require('./cjs/react-server-dom-turbopack-client.browser.production.min.js');
module.exports = require('./cjs/react-server-dom-turbopack-client.browser.production.js');
} else {
module.exports = require('./cjs/react-server-dom-turbopack-client.browser.development.js');
}
2 changes: 1 addition & 1 deletion packages/react-server-dom-turbopack/npm/client.edge.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

if (process.env.NODE_ENV === 'production') {
module.exports = require('./cjs/react-server-dom-turbopack-client.edge.production.min.js');
module.exports = require('./cjs/react-server-dom-turbopack-client.edge.production.js');
} else {
module.exports = require('./cjs/react-server-dom-turbopack-client.edge.development.js');
}
2 changes: 1 addition & 1 deletion packages/react-server-dom-turbopack/npm/client.node.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

if (process.env.NODE_ENV === 'production') {
module.exports = require('./cjs/react-server-dom-turbopack-client.node.production.min.js');
module.exports = require('./cjs/react-server-dom-turbopack-client.node.production.js');
} else {
module.exports = require('./cjs/react-server-dom-turbopack-client.node.development.js');
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

if (process.env.NODE_ENV === 'production') {
module.exports = require('./cjs/react-server-dom-turbopack-client.node.unbundled.production.min.js');
module.exports = require('./cjs/react-server-dom-turbopack-client.node.unbundled.production.js');
} else {
module.exports = require('./cjs/react-server-dom-turbopack-client.node.unbundled.development.js');
}
2 changes: 1 addition & 1 deletion packages/react-server-dom-turbopack/npm/server.browser.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

if (process.env.NODE_ENV === 'production') {
module.exports = require('./cjs/react-server-dom-turbopack-server.browser.production.min.js');
module.exports = require('./cjs/react-server-dom-turbopack-server.browser.production.js');
} else {
module.exports = require('./cjs/react-server-dom-turbopack-server.browser.development.js');
}
2 changes: 1 addition & 1 deletion packages/react-server-dom-turbopack/npm/server.edge.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

if (process.env.NODE_ENV === 'production') {
module.exports = require('./cjs/react-server-dom-turbopack-server.edge.production.min.js');
module.exports = require('./cjs/react-server-dom-turbopack-server.edge.production.js');
} else {
module.exports = require('./cjs/react-server-dom-turbopack-server.edge.development.js');
}
2 changes: 1 addition & 1 deletion packages/react-server-dom-turbopack/npm/server.node.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

if (process.env.NODE_ENV === 'production') {
module.exports = require('./cjs/react-server-dom-turbopack-server.node.production.min.js');
module.exports = require('./cjs/react-server-dom-turbopack-server.node.production.js');
} else {
module.exports = require('./cjs/react-server-dom-turbopack-server.node.development.js');
}
Loading

0 comments on commit 857ee8c

Please sign in to comment.