From 144f2caed897d579c461b69eb34f263b46b38747 Mon Sep 17 00:00:00 2001 From: Tom Najdek Date: Fri, 2 Aug 2024 09:43:02 +0200 Subject: [PATCH] Use production builds of react libraries (#4482) And remove patching that doesn't seem to be required anymore --- .babelrc | 2 -- js-build/babel-worker.js | 13 +------------ js-build/config.js | 12 ++++-------- resource/react-dom-server.js | 2 +- resource/react-dom.js | 2 +- resource/react-intl.js | 2 +- resource/react.js | 2 +- 7 files changed, 9 insertions(+), 26 deletions(-) diff --git a/.babelrc b/.babelrc index 3c72d46bde..e5bdbee907 100644 --- a/.babelrc +++ b/.babelrc @@ -9,8 +9,6 @@ "chrome/content/zotero/xpcom/citeproc.js", "chrome/content/ace/*", "chrome/content/scaffold/templates/*", - "resource/react.js", - "resource/react-dom.js", "resource/react-virtualized.js", "test/resource/*.js" ], diff --git a/js-build/babel-worker.js b/js-build/babel-worker.js index 1b612f0255..1b4920b9a7 100644 --- a/js-build/babel-worker.js +++ b/js-build/babel-worker.js @@ -30,19 +30,8 @@ async function babelWorker(ev) { try { let contents = await fs.readFile(sourcefile, 'utf8'); - // Patch react - if (comparePaths(sourcefile, 'resource/react.js')) { - transformed = contents.replace('instanceof Error', '.constructor.name == "Error"') - } - // Patch react-dom - else if (comparePaths(sourcefile, 'resource/react-dom.js')) { - transformed = contents.replace(/ ownerDocument\.createElement\((.*?)\)/gi, 'ownerDocument.createElementNS(HTML_NAMESPACE, $1)') - .replace('element instanceof win.HTMLIFrameElement', - 'typeof element != "undefined" && element.tagName.toLowerCase() == "iframe"') - .replace("isInputEventSupported = false", 'isInputEventSupported = true'); - } // Patch react-virtualized - else if (comparePaths(sourcefile, 'resource/react-virtualized.js')) { + if (comparePaths(sourcefile, 'resource/react-virtualized.js')) { transformed = contents.replace('scrollDiv = document.createElement("div")', 'scrollDiv = document.createElementNS("http://www.w3.org/1999/xhtml", "div")') .replace('document.body.appendChild(scrollDiv)', 'document.documentElement.appendChild(scrollDiv)') .replace('document.body.removeChild(scrollDiv)', 'document.documentElement.removeChild(scrollDiv)'); diff --git a/js-build/config.js b/js-build/config.js index f1c5df4b64..8c86a784b3 100644 --- a/js-build/config.js +++ b/js-build/config.js @@ -26,14 +26,12 @@ const copyDirs = [ // list of files from root folder to symlink const symlinkFiles = [ 'chrome.manifest', - // React needs to be patched by babel-worker.js, so symlink all files in resource/ except for - // those. Babel transpilation for React is still disabled in .babelrc. + // react-virtualized needs to be patched by babel-worker.js, so symlink all files in resource/ except for + // those. Babel transpilation is still disabled in .babelrc. 'resource/**/*', - '!resource/react.js', - '!resource/react-dom.js', '!resource/react-virtualized.js', // Only include dist directory of singleFile - // Also do a little bit of manipulation similar to React + // Also do a little bit of manipulation similar to react-virtualized '!resource/SingleFile/**/*', 'resource/SingleFile/lib/**/*', '!resource/SingleFile/lib/single-file.js', @@ -116,9 +114,7 @@ const jsFiles = [ `{${dirs.join(',')}}/**/*.jsx`, `!{${symlinkDirs.concat(copyDirs).join(',')}}/**/*.js`, `!{${symlinkDirs.concat(copyDirs).join(',')}}/**/*.jsx`, - // Special handling for React -- see note above - 'resource/react.js', - 'resource/react-dom.js', + // Special handling for react-virtualized and others -- see note above 'resource/react-virtualized.js', 'resource/SingleFile/lib/single-file.js', 'resource/citeproc_rs_wasm.js', diff --git a/resource/react-dom-server.js b/resource/react-dom-server.js index 97d12a4d42..f2412a8fee 120000 --- a/resource/react-dom-server.js +++ b/resource/react-dom-server.js @@ -1 +1 @@ -../node_modules/react-dom/umd/react-dom-server.browser.development.js \ No newline at end of file +../node_modules/react-dom/umd/react-dom-server.browser.production.min.js \ No newline at end of file diff --git a/resource/react-dom.js b/resource/react-dom.js index dcca22f2ff..be5fab50bf 120000 --- a/resource/react-dom.js +++ b/resource/react-dom.js @@ -1 +1 @@ -../node_modules/react-dom/umd/react-dom.development.js \ No newline at end of file +../node_modules/react-dom/umd/react-dom.production.min.js \ No newline at end of file diff --git a/resource/react-intl.js b/resource/react-intl.js index ef64c43adc..355f02ea4e 120000 --- a/resource/react-intl.js +++ b/resource/react-intl.js @@ -1 +1 @@ -../node_modules/react-intl/dist/react-intl.js \ No newline at end of file +../node_modules/react-intl/dist/react-intl.min.js \ No newline at end of file diff --git a/resource/react.js b/resource/react.js index 1af854d8eb..6ec24d0d86 120000 --- a/resource/react.js +++ b/resource/react.js @@ -1 +1 @@ -../node_modules/react/umd/react.development.js \ No newline at end of file +../node_modules/react/umd/react.production.min.js \ No newline at end of file