File tree Expand file tree Collapse file tree 1 file changed +22
-1
lines changed
packages/react-scripts/scripts Expand file tree Collapse file tree 1 file changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -237,8 +237,29 @@ prompts({
237
237
238
238
// Add Babel config
239
239
console . log ( ` Adding ${ cyan ( 'Babel' ) } preset` ) ;
240
+ // Detect if the new JSX transform is available and prefer it after eject
241
+ const hasJsxRuntime = ( ( ) => {
242
+ if ( process . env . DISABLE_NEW_JSX_TRANSFORM === 'true' ) {
243
+ return false ;
244
+ }
245
+ try {
246
+ require . resolve ( 'react/jsx-runtime' ) ;
247
+ return true ;
248
+ } catch ( e ) {
249
+ return false ;
250
+ }
251
+ } ) ( ) ;
252
+
240
253
appPackage . babel = {
241
- presets : [ 'react-app' ] ,
254
+ // Preserve preset with explicit runtime so ejected apps keep working without importing React
255
+ presets : [
256
+ [
257
+ 'react-app' ,
258
+ {
259
+ runtime : hasJsxRuntime ? 'automatic' : 'classic' ,
260
+ } ,
261
+ ] ,
262
+ ] ,
242
263
} ;
243
264
244
265
// Add ESlint config
You can’t perform that action at this time.
0 commit comments