From 1c8380371c7cde2c025647f93bf0456fb976d6ff Mon Sep 17 00:00:00 2001 From: acdlite Date: Sat, 20 Apr 2024 15:29:32 +0000 Subject: [PATCH] Don't minify symbols in production builds (#28881) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. DiffTrain build for [857ee8cdf9af81bc94a7f04528fbda7fb2510eb4](https://github.com/facebook/react/commit/857ee8cdf9af81bc94a7f04528fbda7fb2510eb4) --- compiled/facebook-www/REVISION | 2 +- .../unstable_server-external-runtime.js | 236 +++++++++++++++++- 2 files changed, 236 insertions(+), 2 deletions(-) diff --git a/compiled/facebook-www/REVISION b/compiled/facebook-www/REVISION index f84466e1b800f..94d1ff4a8b20c 100644 --- a/compiled/facebook-www/REVISION +++ b/compiled/facebook-www/REVISION @@ -1 +1 @@ -ea26e38e33bffeba1ecc42688d7e8cd7e0da1c02 +857ee8cdf9af81bc94a7f04528fbda7fb2510eb4 diff --git a/compiled/facebook-www/unstable_server-external-runtime.js b/compiled/facebook-www/unstable_server-external-runtime.js index 8ce78e83b0d85..94e2795456d17 100644 --- a/compiled/facebook-www/unstable_server-external-runtime.js +++ b/compiled/facebook-www/unstable_server-external-runtime.js @@ -1 +1,235 @@ -(function(){function e(e,t,n){t=document.getElementById(t);t.parentNode.removeChild(t);var r=document.getElementById(e);if(r){e=r.previousSibling;if(n)e.data="$!",r.setAttribute("data-dgst",n);else{n=e.parentNode;r=e.nextSibling;var i=0;do{if(r&&8===r.nodeType){var d=r.data;if("/$"===d)if(0===i)break;else i--;else"$"!==d&&"$?"!==d&&"$!"!==d||i++}d=r.nextSibling;n.removeChild(r);r=d}while(r);for(;t.firstChild;)n.insertBefore(t.firstChild,r);e.data="$"}e._reactRetry&&e._reactRetry()}}function t(t,n,r){for(var i=new Map,o=document,a,l,c=o.querySelectorAll("link[data-precedence],style[data-precedence]"),s=[],u=0;l=c[u++];)"not all"===l.getAttribute("media")?s.push(l):("LINK"===l.tagName&&d.set(l.getAttribute("href"),l),i.set(l.dataset.precedence,a=l));l=0;c=[];var m,f;for(u=!0;;){if(u){var v=r[l++];if(!v){u=!1;l=0;continue}var p=!1,b=0;var g=v[b++];if(f=d.get(g)){var h=f._p;p=!0}else{f=o.createElement("link");f.href=g;f.rel="stylesheet";for(f.dataset.precedence=m=v[b++];h=v[b++];)f.setAttribute(h,v[b++]);h=f._p=new Promise((function(e,t){f.onload=e;f.onerror=t}));d.set(g,f)}g=f.getAttribute("media");!h||"l"===h.s||g&&!window.matchMedia(g).matches||c.push(h);if(p)continue}else{f=s[l++];if(!f)break;m=f.getAttribute("data-precedence");f.removeAttribute("media")}p=i.get(m)||a;p===a&&(a=f);i.set(m,f);p?p.parentNode.insertBefore(f,p.nextSibling):(p=o.head,p.insertBefore(f,p.firstChild))}Promise.all(c).then(e.bind(null,t,n,""),e.bind(null,t,n,"Resource failed to load"))}function n(e){e=e.querySelectorAll("template");for(var t=0;t