Skip to content

Commit e26bb67

Browse files
authored
fix!: don't force optimization of jsx-runtime (#132)
1 parent 7663e92 commit e26bb67

File tree

3 files changed

+12
-24
lines changed

3 files changed

+12
-24
lines changed

packages/plugin-react/README.md

+2-4
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,10 @@ react({
3434

3535
### Configure the JSX import source
3636

37-
Control where the JSX factory is imported from. This option is ignored for classic `jsxRuntime`.
37+
Control where the JSX factory is imported from. For TS projects this is inferred from the tsconfig.
3838

3939
```js
40-
react({
41-
jsxImportSource: '@emotion/react',
42-
})
40+
react({ jsxImportSource: '@emotion/react' })
4341
```
4442

4543
## Babel configuration

packages/plugin-react/src/index.ts

+9-20
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ export interface Options {
2727
jsxRuntime?: 'classic' | 'automatic'
2828
/**
2929
* Control where the JSX factory is imported from.
30-
* This option is ignored when `jsxRuntime` is not `"automatic"`.
31-
* @default "react"
30+
* https://esbuild.github.io/api/#jsx-import-source
31+
* For TS projects this is read from tsconfig
3232
*/
3333
jsxImportSource?: string
3434
/**
@@ -314,6 +314,12 @@ export default function viteReact(opts: Options = {}): PluginOption[] {
314314
name: 'vite:react-refresh',
315315
enforce: 'pre',
316316
config: () => ({
317+
optimizeDeps: {
318+
// We can't add `react-dom` because the dependency is `react-dom/client`
319+
// for React 18 while it's `react-dom` for React 17. We'd need to detect
320+
// what React version the user has installed.
321+
include: ['react'],
322+
},
317323
resolve: {
318324
dedupe: ['react', 'react-dom'],
319325
},
@@ -340,24 +346,7 @@ export default function viteReact(opts: Options = {}): PluginOption[] {
340346
},
341347
}
342348

343-
const reactJsxRuntimeId = 'react/jsx-runtime'
344-
const reactJsxDevRuntimeId = 'react/jsx-dev-runtime'
345-
const viteReactJsx: Plugin = {
346-
name: 'vite:react-jsx',
347-
enforce: 'pre',
348-
config() {
349-
return {
350-
optimizeDeps: {
351-
// We can't add `react-dom` because the dependency is `react-dom/client`
352-
// for React 18 while it's `react-dom` for React 17. We'd need to detect
353-
// what React version the user has installed.
354-
include: [reactJsxRuntimeId, reactJsxDevRuntimeId, 'react'],
355-
},
356-
}
357-
},
358-
}
359-
360-
return [viteBabel, viteReactRefresh, useAutomaticRuntime && viteReactJsx]
349+
return [viteBabel, viteReactRefresh]
361350
}
362351

363352
viteReact.preambleCode = preambleCode

playground/ssr-react/vite.config.js

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import react from '@vitejs/plugin-react'
33

44
export default defineConfig({
55
plugins: [react()],
6+
optimizeDeps: { include: ['react/jsx-dev-runtime'] },
67
build: {
78
minify: false,
89
},

0 commit comments

Comments
 (0)