Skip to content

Commit

Permalink
fix: avoid checking optimized react-dom for compiled JSX
Browse files Browse the repository at this point in the history
  • Loading branch information
aleclarson committed Nov 8, 2021
1 parent bb7563c commit e31cfac
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions packages/plugin-react/src/jsx-runtime/restore-jsx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,23 @@ type RestoredJSX = [result: t.File | null | undefined, isCommonJS: boolean]

let babelRestoreJSX: Promise<PluginItem> | 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<RestoredJSX> {
// 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(
Expand All @@ -28,7 +36,7 @@ export async function restoreJSX(
})

if (!hasCompiledJsx) {
return [null, false]
return jsxNotFound
}

// Support modules that use `import {Fragment} from 'react'`
Expand Down

0 comments on commit e31cfac

Please sign in to comment.