Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: Do not run react compiler needlessly #75676

Merged
merged 4 commits into from
Feb 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions packages/next/src/build/babel/loader/get-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,10 @@ function getFreshConfig(
return false
}

if (/[/\\]node_modules[/\\]/.test(filename)) {
return false
}

if (
loaderOptions.reactCompilerExclude &&
loaderOptions.reactCompilerExclude(filename)
Expand Down Expand Up @@ -325,6 +329,10 @@ function getFreshConfig(
}

if (loaderOptions.transformMode === 'standalone') {
if (!reactCompilerPluginsIfEnabled.length) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will this affect other user customized config? if we can have a test to demostrate the change would be great

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will not be affected because of if (loaderOptions.transformMode === 'standalone')

return null
}

options.plugins = [jsx, ...reactCompilerPluginsIfEnabled]
options.presets = [
[
Expand Down Expand Up @@ -458,6 +466,9 @@ export default function getConfig(
const cacheKey = getCacheKey(cacheCharacteristics)
if (configCache.has(cacheKey)) {
const cachedConfig = configCache.get(cacheKey)
if (!cachedConfig) {
return null
}

return {
...cachedConfig,
Expand Down
3 changes: 3 additions & 0 deletions packages/next/src/build/babel/loader/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ export default function transform(
target,
filename,
})
if (!babelConfig) {
return { code: source, map: inputSourceMap }
}
getConfigSpan.stop()

const normalizeSpan = parentSpan.traceChild('babel-turbo-normalize-file')
Expand Down
Loading