Unverified Commit c9ef4bd3 authored by Donny/강동윤's avatar Donny/강동윤 Committed by GitHub

perf: Do not run react compiler needlessly (#75676)

### What?

 - Do not run react compiler for files in `node_modules`.
 - When the react compiler is not enabled, just disable Babel.

### Why?

We were stripping TypeScript and JSX using Babel when the React Compiler was enabled. We don't have to, and we should not.
parent c2085df2
...@@ -273,6 +273,10 @@ function getFreshConfig( ...@@ -273,6 +273,10 @@ function getFreshConfig(
return false return false
} }
if (/[/\\]node_modules[/\\]/.test(filename)) {
return false
}
if ( if (
loaderOptions.reactCompilerExclude && loaderOptions.reactCompilerExclude &&
loaderOptions.reactCompilerExclude(filename) loaderOptions.reactCompilerExclude(filename)
...@@ -325,6 +329,10 @@ function getFreshConfig( ...@@ -325,6 +329,10 @@ function getFreshConfig(
} }
if (loaderOptions.transformMode === 'standalone') { if (loaderOptions.transformMode === 'standalone') {
if (!reactCompilerPluginsIfEnabled.length) {
return null
}
options.plugins = [jsx, ...reactCompilerPluginsIfEnabled] options.plugins = [jsx, ...reactCompilerPluginsIfEnabled]
options.presets = [ options.presets = [
[ [
...@@ -458,6 +466,9 @@ export default function getConfig( ...@@ -458,6 +466,9 @@ export default function getConfig(
const cacheKey = getCacheKey(cacheCharacteristics) const cacheKey = getCacheKey(cacheCharacteristics)
if (configCache.has(cacheKey)) { if (configCache.has(cacheKey)) {
const cachedConfig = configCache.get(cacheKey) const cachedConfig = configCache.get(cacheKey)
if (!cachedConfig) {
return null
}
return { return {
...cachedConfig, ...cachedConfig,
......
...@@ -86,6 +86,9 @@ export default function transform( ...@@ -86,6 +86,9 @@ export default function transform(
target, target,
filename, filename,
}) })
if (!babelConfig) {
return { code: source, map: inputSourceMap }
}
getConfigSpan.stop() getConfigSpan.stop()
const normalizeSpan = parentSpan.traceChild('babel-turbo-normalize-file') const normalizeSpan = parentSpan.traceChild('babel-turbo-normalize-file')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment