@@ -327,9 +327,17 @@ export function oxcPlugin(config: ResolvedConfig): Plugin {
327
327
? createFilter ( jsxRefreshInclude , jsxRefreshExclude )
328
328
: undefined
329
329
330
+ const jsxImportSource =
331
+ ( typeof oxcTransformOptions . jsx === 'object' &&
332
+ oxcTransformOptions . jsx . importSource ) ||
333
+ 'react'
334
+ const jsxImportRuntime = `${ jsxImportSource } /jsx-runtime`
335
+ const jsxImportDevRuntime = `${ jsxImportSource } /jsx-dev-runtime`
336
+
330
337
const getModifiedOxcTransformOptions = (
331
338
oxcTransformOptions : OxcTransformOptions ,
332
339
id : string ,
340
+ code : string ,
333
341
environment : Environment ,
334
342
) : OxcTransformOptions => {
335
343
const result : OxcTransformOptions = {
@@ -339,11 +347,22 @@ export function oxcPlugin(config: ResolvedConfig): Plugin {
339
347
}
340
348
341
349
const jsxOptions = result . jsx
350
+
351
+ // disable refresh based by the same condition as @vitejs /plugin-react
352
+ // https://github.com/vitejs/vite-plugin-react/blob/c8ecad052001b6fc42e508f18433e6b305bca641/packages/plugin-react/src/index.ts#L261-L269
353
+ const [ filepath ] = id . split ( '?' )
354
+ const isJSX = filepath . endsWith ( 'x' )
355
+
342
356
if (
343
357
typeof jsxOptions === 'object' &&
344
358
jsxOptions . refresh &&
345
359
( environment . config . consumer === 'server' ||
346
- ( jsxRefreshFilter && ! jsxRefreshFilter ( id ) ) )
360
+ ( jsxRefreshFilter && ! jsxRefreshFilter ( id ) ) ||
361
+ ! (
362
+ isJSX ||
363
+ code . includes ( jsxImportRuntime ) ||
364
+ code . includes ( jsxImportDevRuntime )
365
+ ) )
347
366
) {
348
367
result . jsx = { ...jsxOptions , refresh : false }
349
368
}
@@ -380,6 +399,7 @@ export function oxcPlugin(config: ResolvedConfig): Plugin {
380
399
const modifiedOxcTransformOptions = getModifiedOxcTransformOptions (
381
400
oxcTransformOptions ,
382
401
id ,
402
+ code ,
383
403
this . environment ,
384
404
)
385
405
const result = await transformWithOxc (
0 commit comments