From 69b65312689acab9667f8a570cf253f2733ae8e0 Mon Sep 17 00:00:00 2001 From: Andrei <168741329+andreiborza@users.noreply.github.com> Date: Fri, 5 Jul 2024 09:42:35 +0200 Subject: [PATCH] fix(react): Revert back to `jsxRuntime: 'classic'` to prevent breaking react 17 (#12775) Undoes some of the changes in https://github.com/getsentry/sentry-javascript/pull/12204 and https://github.com/getsentry/sentry-javascript/pull/12740 to fix https://github.com/getsentry/sentry-javascript/issues/12608. --- dev-packages/rollup-utils/npmHelpers.mjs | 4 ++-- .../rollup-utils/plugins/make-esm-plugin.mjs | 15 --------------- packages/react/rollup.npm.config.mjs | 4 +++- packages/remix/rollup.npm.config.mjs | 4 +++- 4 files changed, 8 insertions(+), 19 deletions(-) diff --git a/dev-packages/rollup-utils/npmHelpers.mjs b/dev-packages/rollup-utils/npmHelpers.mjs index e95e63700c09..410d0847d928 100644 --- a/dev-packages/rollup-utils/npmHelpers.mjs +++ b/dev-packages/rollup-utils/npmHelpers.mjs @@ -22,7 +22,7 @@ import { makeSetSDKSourcePlugin, makeSucrasePlugin, } from './plugins/index.mjs'; -import { makePackageNodeEsm, makeReactEsmJsxRuntimePlugin } from './plugins/make-esm-plugin.mjs'; +import { makePackageNodeEsm } from './plugins/make-esm-plugin.mjs'; import { mergePlugins } from './utils.mjs'; const __dirname = path.dirname(fileURLToPath(import.meta.url)); @@ -143,7 +143,7 @@ export function makeNPMConfigVariants(baseConfig, options = {}) { output: { format: 'esm', dir: path.join(baseConfig.output.dir, 'esm'), - plugins: [makePackageNodeEsm(), makeReactEsmJsxRuntimePlugin()], + plugins: [makePackageNodeEsm()], }, }); } diff --git a/dev-packages/rollup-utils/plugins/make-esm-plugin.mjs b/dev-packages/rollup-utils/plugins/make-esm-plugin.mjs index 91aba689f888..04dd68beaa1c 100644 --- a/dev-packages/rollup-utils/plugins/make-esm-plugin.mjs +++ b/dev-packages/rollup-utils/plugins/make-esm-plugin.mjs @@ -1,5 +1,4 @@ import fs from 'node:fs'; -import replacePlugin from '@rollup/plugin-replace'; /** * Outputs a package.json file with {type: module} in the root of the output directory so that Node @@ -30,17 +29,3 @@ export function makePackageNodeEsm() { }, }; } - -/** - * Makes sure that whenever we add an `react/jsx-runtime` import, we add a `.js` to make the import esm compatible. - */ -export function makeReactEsmJsxRuntimePlugin() { - return replacePlugin({ - preventAssignment: false, - sourceMap: true, - values: { - "'react/jsx-runtime'": "'react/jsx-runtime.js'", - '"react/jsx-runtime"': '"react/jsx-runtime.js"', - }, - }); -} diff --git a/packages/react/rollup.npm.config.mjs b/packages/react/rollup.npm.config.mjs index e4b28f60a4a6..4014705e5eb4 100644 --- a/packages/react/rollup.npm.config.mjs +++ b/packages/react/rollup.npm.config.mjs @@ -7,7 +7,9 @@ export default makeNPMConfigVariants( external: ['react', 'react/jsx-runtime'], }, sucrase: { - jsxRuntime: 'automatic', // React 19 emits a warning if we don't use the newer jsx transform: https://legacy.reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html + // React 19 emits a warning if we don't use the newer jsx transform: https://legacy.reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html + // but this breaks react 17, so we keep it at `classic` for now + jsxRuntime: 'classic', production: true, // This is needed so that sucrase uses the production jsx runtime (ie `import { jsx } from 'react/jsx-runtime'` instead of `import { jsxDEV as _jsxDEV } from 'react/jsx-dev-runtime'`) }, }), diff --git a/packages/remix/rollup.npm.config.mjs b/packages/remix/rollup.npm.config.mjs index 60779af94f6b..346e043eb0f9 100644 --- a/packages/remix/rollup.npm.config.mjs +++ b/packages/remix/rollup.npm.config.mjs @@ -12,7 +12,9 @@ export default [ }, }, sucrase: { - jsxRuntime: 'automatic', // React 19 emits a warning if we don't use the newer jsx transform: https://legacy.reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html + // React 19 emits a warning if we don't use the newer jsx transform: https://legacy.reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html + // but this breaks react 17, so we keep it at `classic` for now + jsxRuntime: 'classic', production: true, // This is needed so that sucrase uses the production jsx runtime (ie `import { jsx } from 'react/jsx-runtime'` instead of `import { jsxDEV as _jsxDEV } from 'react/jsx-dev-runtime'`) }, }),