Skip to content

Commit 074ab46

Browse files
authored
chore: deprecate classic runtime (#131)
1 parent 40b83e3 commit 074ab46

2 files changed

Lines changed: 7 additions & 32 deletions

File tree

packages/plugin-react/README.md

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
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
6+
- use the [automatic JSX runtime](https://legacy.reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html)
87
- dedupe the `react` and `react-dom` packages
98
- use custom Babel plugins/presets
109

@@ -43,16 +42,6 @@ react({
4342
})
4443
```
4544

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-
5645
## Babel configuration
5746

5847
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
@@ -20,7 +20,8 @@ export interface Options {
2020
*/
2121
fastRefresh?: boolean
2222
/**
23-
* Set this to `"automatic"` to use [vite-react-jsx](https://github.com/alloc/vite-react-jsx).
23+
* @deprecated All tools now support the automatic runtime, and it has been backported
24+
* up to React 16. This allows to skip the React import and can produce smaller bundlers.
2425
* @default "automatic"
2526
*/
2627
jsxRuntime?: 'classic' | 'automatic'
@@ -97,7 +98,7 @@ export default function viteReact(opts: Options = {}): PluginOption[] {
9798
let isProduction = true
9899
let projectRoot = process.cwd()
99100
let skipFastRefresh = opts.fastRefresh === false
100-
let skipReactImport = false
101+
const skipReactImport = false
101102
let runPluginOverrides = (
102103
options: ReactBabelOptions,
103104
context: ReactBabelHookContext,
@@ -151,27 +152,12 @@ export default function viteReact(opts: Options = {}): PluginOption[] {
151152
isProduction = config.isProduction
152153
skipFastRefresh ||= isProduction || config.command === 'build'
153154

154-
const jsxInject = config.esbuild && config.esbuild.jsxInject
155-
if (jsxInject && importReactRE.test(jsxInject)) {
156-
skipReactImport = true
157-
config.logger.warn(
158-
'[@vitejs/plugin-react] This plugin imports React for you automatically,' +
159-
' so you can stop using `esbuild.jsxInject` for that purpose.',
155+
if (opts.jsxRuntime === 'classic') {
156+
config.logger.warnOnce(
157+
'[@vitejs/plugin-react] Support for classic runtime is deprecated.',
160158
)
161159
}
162160

163-
config.plugins.forEach((plugin) => {
164-
const hasConflict =
165-
plugin.name === 'react-refresh' ||
166-
(plugin !== viteReactJsx && plugin.name === 'vite:react-jsx')
167-
168-
if (hasConflict)
169-
return config.logger.warn(
170-
`[@vitejs/plugin-react] You should stop using "${plugin.name}" ` +
171-
`since this plugin conflicts with it.`,
172-
)
173-
})
174-
175161
runPluginOverrides = (babelOptions, context) => {
176162
const hooks = config.plugins
177163
.map((plugin) => plugin.api?.reactBabel)

0 commit comments

Comments
 (0)