diff --git a/packages/plugin-react/src/jsx-runtime/restore-jsx.ts b/packages/plugin-react/src/jsx-runtime/restore-jsx.ts index 0d4f34eb2b8d00..250fe43ce4d0c8 100644 --- a/packages/plugin-react/src/jsx-runtime/restore-jsx.ts +++ b/packages/plugin-react/src/jsx-runtime/restore-jsx.ts @@ -4,15 +4,23 @@ type RestoredJSX = [result: t.File | null | undefined, isCommonJS: boolean] let babelRestoreJSX: Promise | undefined +const jsxNotFound: RestoredJSX = [null, false] + /** Restore JSX from `React.createElement` calls */ export async function restoreJSX( babel: typeof import('@babel/core'), code: string, filename: string ): Promise { + // Avoid parsing the optimized react-dom since it will never + // contain compiled JSX and it's a pretty big file (800kb). + if (filename.includes('/.vite/react-dom.js')) { + return jsxNotFound + } + const [reactAlias, isCommonJS] = parseReactAlias(code) if (!reactAlias) { - return [null, false] + return jsxNotFound } const reactJsxRE = new RegExp( @@ -28,7 +36,7 @@ export async function restoreJSX( }) if (!hasCompiledJsx) { - return [null, false] + return jsxNotFound } // Support modules that use `import {Fragment} from 'react'`