@@ -8,6 +8,7 @@ import type { NextBabelLoaderOptions, NextJsLoaderContext } from './types'
8
8
import { consumeIterator } from './util'
9
9
import * as Log from '../../output/log'
10
10
import jsx from 'next/dist/compiled/babel/plugin-syntax-jsx'
11
+ import { isReactCompilerRequired } from '../../swc'
11
12
12
13
const nextDistPath =
13
14
/ ( 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(
257
258
* Generate a new, flat Babel config, ready to be handed to Babel-traverse.
258
259
* This config should have no unresolved overrides, presets, etc.
259
260
*/
260
- function getFreshConfig (
261
+ async function getFreshConfig (
261
262
this : NextJsLoaderContext ,
262
263
cacheCharacteristics : CharacteristicsGermaneToCaching ,
263
264
loaderOptions : NextBabelLoaderOptions ,
264
265
target : string ,
265
266
filename : string ,
266
267
inputSourceMap ?: object | null
267
268
) {
268
- const hasReactCompiler = ( ( ) => {
269
+ const hasReactCompiler = await ( async ( ) => {
269
270
if (
270
271
loaderOptions . reactCompilerPlugins &&
271
272
loaderOptions . reactCompilerPlugins . length === 0
@@ -284,6 +285,10 @@ function getFreshConfig(
284
285
return false
285
286
}
286
287
288
+ if ( ! ( await isReactCompilerRequired ( filename ) ) ) {
289
+ return false
290
+ }
291
+
287
292
return true
288
293
} ) ( )
289
294
@@ -436,7 +441,7 @@ type BabelConfig = any
436
441
const configCache : Map < any , BabelConfig > = new Map ( )
437
442
const configFiles : Set < string > = new Set ( )
438
443
439
- export default function getConfig (
444
+ export default async function getConfig (
440
445
this : NextJsLoaderContext ,
441
446
{
442
447
source,
@@ -451,7 +456,7 @@ export default function getConfig(
451
456
filename : string
452
457
inputSourceMap ?: object | null
453
458
}
454
- ) : BabelConfig {
459
+ ) : Promise < BabelConfig > {
455
460
const cacheCharacteristics = getCacheCharacteristics (
456
461
loaderOptions ,
457
462
source ,
@@ -493,7 +498,7 @@ export default function getConfig(
493
498
)
494
499
}
495
500
496
- const freshConfig = getFreshConfig . call (
501
+ const freshConfig = await getFreshConfig . call (
497
502
this ,
498
503
cacheCharacteristics ,
499
504
loaderOptions ,
0 commit comments