@@ -8,6 +8,7 @@ import type { NextBabelLoaderOptions, NextJsLoaderContext } from './types'
88import { consumeIterator } from './util'
99import * as Log from '../../output/log'
1010import jsx from 'next/dist/compiled/babel/plugin-syntax-jsx'
11+ import { isReactCompilerRequired } from '../../swc'
1112
1213const nextDistPath =
1314/ ( n e x t [ \\ / ] d i s t [ \\ / ] s h a r e d [ \\ / ] l i b ) | ( n e x t [ \\ / ] d i s t [ \\ / ] c l i e n t ) | ( n e x t [ \\ / ] d i s t [ \\ / ] p a g e s ) /
@@ -257,15 +258,15 @@ function checkCustomBabelConfigDeprecation(
257258 * Generate a new, flat Babel config, ready to be handed to Babel-traverse.
258259 * This config should have no unresolved overrides, presets, etc.
259260 */
260- function getFreshConfig (
261+ async function getFreshConfig (
261262this :NextJsLoaderContext ,
262263cacheCharacteristics :CharacteristicsGermaneToCaching ,
263264loaderOptions :NextBabelLoaderOptions ,
264265target :string ,
265266filename :string ,
266267inputSourceMap ?:object | null
267268) {
268- const hasReactCompiler = ( ( ) => {
269+ const hasReactCompiler = await ( async ( ) => {
269270if (
270271loaderOptions . reactCompilerPlugins &&
271272loaderOptions . reactCompilerPlugins . length === 0
@@ -284,6 +285,10 @@ function getFreshConfig(
284285return false
285286}
286287
288+ if ( ! ( await isReactCompilerRequired ( filename ) ) ) {
289+ return false
290+ }
291+
287292return true
288293} ) ( )
289294
@@ -436,7 +441,7 @@ type BabelConfig = any
436441const configCache :Map < any , BabelConfig > = new Map ( )
437442const configFiles :Set < string > = new Set ( )
438443
439- export default function getConfig (
444+ export default async function getConfig (
440445this :NextJsLoaderContext ,
441446{
442447 source,
@@ -451,7 +456,7 @@ export default function getConfig(
451456filename :string
452457inputSourceMap ?:object | null
453458}
454- ) :BabelConfig {
459+ ) :Promise < BabelConfig > {
455460const cacheCharacteristics = getCacheCharacteristics (
456461loaderOptions ,
457462source ,
@@ -493,7 +498,7 @@ export default function getConfig(
493498)
494499}
495500
496- const freshConfig = getFreshConfig . call (
501+ const freshConfig = await getFreshConfig . call (
497502this ,
498503cacheCharacteristics ,
499504loaderOptions ,