Skip to content

Commit 0ebaa73

Browse files
committed
chore: deprecate classic runtime
1 parent a1b4de1 commit 0ebaa73

File tree

2 files changed

+6
-32
lines changed

2 files changed

+6
-32
lines changed

packages/plugin-react/README.md

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
The all-in-one Vite plugin for React projects.
44

55
- enable [Fast Refresh](https://www.npmjs.com/package/react-refresh) in development
6-
- use the [automatic JSX runtime](https://github.com/alloc/vite-react-jsx#faq)
7-
- avoid manual `import React` in `.jsx` and `.tsx` modules
86
- dedupe the `react` and `react-dom` packages
97
- use custom Babel plugins/presets
108

@@ -43,16 +41,6 @@ react({
4341
})
4442
```
4543

46-
## Opting out of the automatic JSX runtime
47-
48-
By default, the plugin uses the [automatic JSX runtime](https://github.com/alloc/vite-react-jsx#faq). However, if you encounter any issues, you may opt out using the `jsxRuntime` option.
49-
50-
```js
51-
react({
52-
jsxRuntime: 'classic',
53-
})
54-
```
55-
5644
## Babel configuration
5745

5846
The `babel` option lets you add plugins, presets, and [other configuration](https://babeljs.io/docs/en/options) to the Babel transformation performed on each JSX/TSX file.

packages/plugin-react/src/index.ts

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ export interface Options {
2121
*/
2222
fastRefresh?: boolean
2323
/**
24-
* Set this to `"automatic"` to use [vite-react-jsx](https://github.com/alloc/vite-react-jsx).
24+
* @deprecated All tools now support the automatic runtime, and it has been backported
25+
* up to React 16. This allows to skip the React import and can produce smaller bundlers.
2526
* @default "automatic"
2627
*/
2728
jsxRuntime?: 'classic' | 'automatic'
@@ -98,7 +99,7 @@ export default function viteReact(opts: Options = {}): PluginOption[] {
9899
let isProduction = true
99100
let projectRoot = process.cwd()
100101
let skipFastRefresh = opts.fastRefresh === false
101-
let skipReactImport = false
102+
const skipReactImport = false
102103
let runPluginOverrides = (
103104
options: ReactBabelOptions,
104105
context: ReactBabelHookContext,
@@ -167,27 +168,12 @@ export default function viteReact(opts: Options = {}): PluginOption[] {
167168
isProduction = config.isProduction
168169
skipFastRefresh ||= isProduction || config.command === 'build'
169170

170-
const jsxInject = config.esbuild && config.esbuild.jsxInject
171-
if (jsxInject && importReactRE.test(jsxInject)) {
172-
skipReactImport = true
173-
config.logger.warn(
174-
'[@vitejs/plugin-react] This plugin imports React for you automatically,' +
175-
' so you can stop using `esbuild.jsxInject` for that purpose.',
171+
if (opts.jsxRuntime === 'classic') {
172+
config.logger.warnOnce(
173+
'[@vitejs/plugin-react] Support for classic runtime is deprecated.',
176174
)
177175
}
178176

179-
config.plugins.forEach((plugin) => {
180-
const hasConflict =
181-
plugin.name === 'react-refresh' ||
182-
(plugin !== viteReactJsx && plugin.name === 'vite:react-jsx')
183-
184-
if (hasConflict)
185-
return config.logger.warn(
186-
`[@vitejs/plugin-react] You should stop using "${plugin.name}" ` +
187-
`since this plugin conflicts with it.`,
188-
)
189-
})
190-
191177
runPluginOverrides = (babelOptions, context) => {
192178
const hooks = config.plugins
193179
.map((plugin) => plugin.api?.reactBabel)

0 commit comments

Comments
 (0)