Skip to content

Commit

Permalink
Don't minify symbols in production builds
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 facebook#28827 and facebook#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 committed Apr 19, 2024
1 parent 0e0b693 commit 9f02628
Show file tree
Hide file tree
Showing 98 changed files with 263 additions and 292 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
4 changes: 2 additions & 2 deletions fixtures/legacy-jsx-runtimes/lint-runtimes.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ async function lint(folder) {

const results = await eslint.lintFiles([
__dirname + '/' + folder + '/cjs/react-jsx-dev-runtime.development.js',
__dirname + '/' + folder + '/cjs/react-jsx-dev-runtime.production.min.js',
__dirname + '/' + folder + '/cjs/react-jsx-dev-runtime.production.js',
__dirname + '/' + folder + '/cjs/react-jsx-runtime.development.js',
__dirname + '/' + folder + '/cjs/react-jsx-runtime.production.min.js',
__dirname + '/' + folder + '/cjs/react-jsx-runtime.production.js',
]);
if (
results.some(result => result.errorCount > 0 || result.warningCount > 0)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
/** @license React v0.14.10
* react-jsx-dev-runtime.production.min.js
* react-jsx-dev-runtime.production.js
*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
'use strict';require("react");exports.Fragment=60107;if("function"===typeof Symbol&&Symbol.for){var a=Symbol.for;exports.Fragment=a("react.fragment")}exports.jsxDEV=void 0;
'use strict';
require('react');
exports.Fragment = 60107;
if ('function' === typeof Symbol && Symbol.for) {
var a = Symbol.for;
exports.Fragment = a('react.fragment');
}
exports.jsxDEV = void 0;
Original file line number Diff line number Diff line change
@@ -1,10 +1,35 @@
/** @license React v0.14.10
* react-jsx-runtime.production.min.js
* react-jsx-runtime.production.js
*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
'use strict';var f=require("react"),g=60103;exports.Fragment=60107;if("function"===typeof Symbol&&Symbol.for){var h=Symbol.for;g=h("react.element");exports.Fragment=h("react.fragment")}var m=require("react/lib/ReactCurrentOwner"),n=Object.prototype.hasOwnProperty,p={key:!0,ref:!0,__self:!0,__source:!0};
function q(c,a,k){var b,d={},e=null,l=null;void 0!==k&&(e=""+k);void 0!==a.key&&(e=""+a.key);void 0!==a.ref&&(l=a.ref);for(b in a)n.call(a,b)&&!p.hasOwnProperty(b)&&(d[b]=a[b]);if(c&&c.defaultProps)for(b in a=c.defaultProps,a)void 0===d[b]&&(d[b]=a[b]);return{$$typeof:g,type:c,key:e,ref:l,props:d,_owner:m.current}}exports.jsx=q;exports.jsxs=q;
'use strict';
var f = require('react'),
g = 60103;
exports.Fragment = 60107;
if ('function' === typeof Symbol && Symbol.for) {
var h = Symbol.for;
g = h('react.element');
exports.Fragment = h('react.fragment');
}
var m = require('react/lib/ReactCurrentOwner'),
n = Object.prototype.hasOwnProperty,
p = {key: !0, ref: !0, __self: !0, __source: !0};
function q(c, a, k) {
var b,
d = {},
e = null,
l = null;
void 0 !== k && (e = '' + k);
void 0 !== a.key && (e = '' + a.key);
void 0 !== a.ref && (l = a.ref);
for (b in a) n.call(a, b) && !p.hasOwnProperty(b) && (d[b] = a[b]);
if (c && c.defaultProps)
for (b in ((a = c.defaultProps), a)) void 0 === d[b] && (d[b] = a[b]);
return {$$typeof: g, type: c, key: e, ref: l, props: d, _owner: m.current};
}
exports.jsx = q;
exports.jsxs = q;
2 changes: 1 addition & 1 deletion fixtures/legacy-jsx-runtimes/react-14/jsx-dev-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-jsx-dev-runtime.production.min.js');
module.exports = require('./cjs/react-jsx-dev-runtime.production.js');
} else {
module.exports = require('./cjs/react-jsx-dev-runtime.development.js');
}
2 changes: 1 addition & 1 deletion fixtures/legacy-jsx-runtimes/react-14/jsx-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-jsx-runtime.production.min.js');
module.exports = require('./cjs/react-jsx-runtime.production.js');
} else {
module.exports = require('./cjs/react-jsx-runtime.development.js');
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
/** @license React v15.7.0
* react-jsx-dev-runtime.production.min.js
* react-jsx-dev-runtime.production.js
*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
'use strict';require("react");exports.Fragment=60107;if("function"===typeof Symbol&&Symbol.for){var a=Symbol.for;exports.Fragment=a("react.fragment")}exports.jsxDEV=void 0;
'use strict';
require('react');
exports.Fragment = 60107;
if ('function' === typeof Symbol && Symbol.for) {
var a = Symbol.for;
exports.Fragment = a('react.fragment');
}
exports.jsxDEV = void 0;
Original file line number Diff line number Diff line change
@@ -1,10 +1,35 @@
/** @license React v15.7.0
* react-jsx-runtime.production.min.js
* react-jsx-runtime.production.js
*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
'use strict';var f=require("react"),g=60103;exports.Fragment=60107;if("function"===typeof Symbol&&Symbol.for){var h=Symbol.for;g=h("react.element");exports.Fragment=h("react.fragment")}var m=require("react/lib/ReactCurrentOwner"),n=Object.prototype.hasOwnProperty,p={key:!0,ref:!0,__self:!0,__source:!0};
function q(c,a,k){var b,d={},e=null,l=null;void 0!==k&&(e=""+k);void 0!==a.key&&(e=""+a.key);void 0!==a.ref&&(l=a.ref);for(b in a)n.call(a,b)&&!p.hasOwnProperty(b)&&(d[b]=a[b]);if(c&&c.defaultProps)for(b in a=c.defaultProps,a)void 0===d[b]&&(d[b]=a[b]);return{$$typeof:g,type:c,key:e,ref:l,props:d,_owner:m.current}}exports.jsx=q;exports.jsxs=q;
'use strict';
var f = require('react'),
g = 60103;
exports.Fragment = 60107;
if ('function' === typeof Symbol && Symbol.for) {
var h = Symbol.for;
g = h('react.element');
exports.Fragment = h('react.fragment');
}
var m = require('react/lib/ReactCurrentOwner'),
n = Object.prototype.hasOwnProperty,
p = {key: !0, ref: !0, __self: !0, __source: !0};
function q(c, a, k) {
var b,
d = {},
e = null,
l = null;
void 0 !== k && (e = '' + k);
void 0 !== a.key && (e = '' + a.key);
void 0 !== a.ref && (l = a.ref);
for (b in a) n.call(a, b) && !p.hasOwnProperty(b) && (d[b] = a[b]);
if (c && c.defaultProps)
for (b in ((a = c.defaultProps), a)) void 0 === d[b] && (d[b] = a[b]);
return {$$typeof: g, type: c, key: e, ref: l, props: d, _owner: m.current};
}
exports.jsx = q;
exports.jsxs = q;
2 changes: 1 addition & 1 deletion fixtures/legacy-jsx-runtimes/react-15/jsx-dev-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-jsx-dev-runtime.production.min.js');
module.exports = require('./cjs/react-jsx-dev-runtime.production.js');
} else {
module.exports = require('./cjs/react-jsx-dev-runtime.development.js');
}
2 changes: 1 addition & 1 deletion fixtures/legacy-jsx-runtimes/react-15/jsx-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-jsx-runtime.production.min.js');
module.exports = require('./cjs/react-jsx-runtime.production.js');
} else {
module.exports = require('./cjs/react-jsx-runtime.development.js');
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
/** @license React v16.14.0
* react-jsx-dev-runtime.production.min.js
* react-jsx-dev-runtime.production.js
*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
'use strict';require("react");exports.Fragment=60107;if("function"===typeof Symbol&&Symbol.for){var a=Symbol.for;exports.Fragment=a("react.fragment")}exports.jsxDEV=void 0;
'use strict';
require('react');
exports.Fragment = 60107;
if ('function' === typeof Symbol && Symbol.for) {
var a = Symbol.for;
exports.Fragment = a('react.fragment');
}
exports.jsxDEV = void 0;
Original file line number Diff line number Diff line change
@@ -1,10 +1,35 @@
/** @license React v16.14.0
* react-jsx-runtime.production.min.js
* react-jsx-runtime.production.js
*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
'use strict';var f=require("react"),g=60103;exports.Fragment=60107;if("function"===typeof Symbol&&Symbol.for){var h=Symbol.for;g=h("react.element");exports.Fragment=h("react.fragment")}var m=f.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,n=Object.prototype.hasOwnProperty,p={key:!0,ref:!0,__self:!0,__source:!0};
function q(c,a,k){var b,d={},e=null,l=null;void 0!==k&&(e=""+k);void 0!==a.key&&(e=""+a.key);void 0!==a.ref&&(l=a.ref);for(b in a)n.call(a,b)&&!p.hasOwnProperty(b)&&(d[b]=a[b]);if(c&&c.defaultProps)for(b in a=c.defaultProps,a)void 0===d[b]&&(d[b]=a[b]);return{$$typeof:g,type:c,key:e,ref:l,props:d,_owner:m.current}}exports.jsx=q;exports.jsxs=q;
'use strict';
var f = require('react'),
g = 60103;
exports.Fragment = 60107;
if ('function' === typeof Symbol && Symbol.for) {
var h = Symbol.for;
g = h('react.element');
exports.Fragment = h('react.fragment');
}
var m = f.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,
n = Object.prototype.hasOwnProperty,
p = {key: !0, ref: !0, __self: !0, __source: !0};
function q(c, a, k) {
var b,
d = {},
e = null,
l = null;
void 0 !== k && (e = '' + k);
void 0 !== a.key && (e = '' + a.key);
void 0 !== a.ref && (l = a.ref);
for (b in a) n.call(a, b) && !p.hasOwnProperty(b) && (d[b] = a[b]);
if (c && c.defaultProps)
for (b in ((a = c.defaultProps), a)) void 0 === d[b] && (d[b] = a[b]);
return {$$typeof: g, type: c, key: e, ref: l, props: d, _owner: m.current};
}
exports.jsx = q;
exports.jsxs = q;
2 changes: 1 addition & 1 deletion fixtures/legacy-jsx-runtimes/react-16/jsx-dev-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-jsx-dev-runtime.production.min.js');
module.exports = require('./cjs/react-jsx-dev-runtime.production.js');
} else {
module.exports = require('./cjs/react-jsx-dev-runtime.development.js');
}
2 changes: 1 addition & 1 deletion fixtures/legacy-jsx-runtimes/react-16/jsx-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-jsx-runtime.production.min.js');
module.exports = require('./cjs/react-jsx-runtime.production.js');
} else {
module.exports = require('./cjs/react-jsx-runtime.development.js');
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
/** @license React v17.0.0-rc.3
* react-jsx-dev-runtime.production.min.js
* react-jsx-dev-runtime.production.js
*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
'use strict';require("object-assign");require("react");exports.Fragment=60107;if("function"===typeof Symbol&&Symbol.for){var a=Symbol.for;exports.Fragment=a("react.fragment")}exports.jsxDEV=void 0;
'use strict';
require('object-assign');
require('react');
exports.Fragment = 60107;
if ('function' === typeof Symbol && Symbol.for) {
var a = Symbol.for;
exports.Fragment = a('react.fragment');
}
exports.jsxDEV = void 0;
Original file line number Diff line number Diff line change
@@ -1,10 +1,36 @@
/** @license React v17.0.0-rc.3
* react-jsx-runtime.production.min.js
* react-jsx-runtime.production.js
*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
'use strict';require("object-assign");var f=require("react"),g=60103;exports.Fragment=60107;if("function"===typeof Symbol&&Symbol.for){var h=Symbol.for;g=h("react.element");exports.Fragment=h("react.fragment")}var m=f.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,n=Object.prototype.hasOwnProperty,p={key:!0,ref:!0,__self:!0,__source:!0};
function q(c,a,k){var b,d={},e=null,l=null;void 0!==k&&(e=""+k);void 0!==a.key&&(e=""+a.key);void 0!==a.ref&&(l=a.ref);for(b in a)n.call(a,b)&&!p.hasOwnProperty(b)&&(d[b]=a[b]);if(c&&c.defaultProps)for(b in a=c.defaultProps,a)void 0===d[b]&&(d[b]=a[b]);return{$$typeof:g,type:c,key:e,ref:l,props:d,_owner:m.current}}exports.jsx=q;exports.jsxs=q;
'use strict';
require('object-assign');
var f = require('react'),
g = 60103;
exports.Fragment = 60107;
if ('function' === typeof Symbol && Symbol.for) {
var h = Symbol.for;
g = h('react.element');
exports.Fragment = h('react.fragment');
}
var m = f.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,
n = Object.prototype.hasOwnProperty,
p = {key: !0, ref: !0, __self: !0, __source: !0};
function q(c, a, k) {
var b,
d = {},
e = null,
l = null;
void 0 !== k && (e = '' + k);
void 0 !== a.key && (e = '' + a.key);
void 0 !== a.ref && (l = a.ref);
for (b in a) n.call(a, b) && !p.hasOwnProperty(b) && (d[b] = a[b]);
if (c && c.defaultProps)
for (b in ((a = c.defaultProps), a)) void 0 === d[b] && (d[b] = a[b]);
return {$$typeof: g, type: c, key: e, ref: l, props: d, _owner: m.current};
}
exports.jsx = q;
exports.jsxs = q;
2 changes: 1 addition & 1 deletion fixtures/legacy-jsx-runtimes/react-17/jsx-dev-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-jsx-dev-runtime.production.min.js');
module.exports = require('./cjs/react-jsx-dev-runtime.production.js');
} else {
module.exports = require('./cjs/react-jsx-dev-runtime.development.js');
}
2 changes: 1 addition & 1 deletion fixtures/legacy-jsx-runtimes/react-17/jsx-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-jsx-runtime.production.min.js');
module.exports = require('./cjs/react-jsx-runtime.production.js');
} else {
module.exports = require('./cjs/react-jsx-runtime.development.js');
}
5 changes: 2 additions & 3 deletions fixtures/packaging/systemjs-builder/prod/config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
System.config({
paths: {
react:
'../../../../build/oss-experimental/react/umd/react.production.min.js',
react: '../../../../build/oss-experimental/react/umd/react.production.js',
'react-dom':
'../../../../build/oss-experimental/react-dom/umd/react-dom.production.min.js',
'../../../../build/oss-experimental/react-dom/umd/react-dom.production.js',
schedule:
'../../../../build/oss-experimental/scheduler/umd/schedule.development',
},
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');
}
Loading

0 comments on commit 9f02628

Please sign in to comment.