-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat!: transform jsx with esbuild instead of babel #9590
Conversation
Thanks for the PR @rtsao! The change looks good to me. About @aleclarson @frandiox @cyco130 would you check how this PR works in your projects? I think we could release it in a new major for plugin-react. |
This doesn't work right now: It results in syntax errors because it leaves JSX untransformed in some cases. It seems to be because of the I'll look into it a bit more and try to create a reproduction but I don't see a quick fix (apart from removing the |
Turns out it requires an uncommon combination: a React component in
|
TLDR: We have two problems. 1. Repro tomorrow. |
I have created a vite plugin for this purpose. I made some changes, removed Now it can work normally at present also a lot faster |
I confirm, using this plugin, dev server does feels faster. Will try and put comparison numbers tomorrow. |
This comment was marked as spam.
This comment was marked as spam.
* Toggles whether or not to throw an error if an XML namespaced tag name is used. | ||
* @default true | ||
*/ | ||
jsxThrowIfNamespace?: boolean |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I saw this option was added in #9571
This is not a breaking change as esbuild supports JSX namespaces: evanw/esbuild@71240d4
So Vite would not throw transforming JSX namespaces and thus this option is no longer needed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your work and patience with this PR @rtsao. Let's merge it and release an alpha for the next version of plugin react, so we can test it and release it together with Vite 4. Also taking into account here the previous review from @aleclarson.
If you are interested in getting more involved with this plugin @rtsao, reach out to us at https://chat.vitejs.dev in the #contributing channel. For context, we are planning to move this plugin (and plugin-vue and plugin-vue-jsx) out of the Vite core monorepo. We think that using vite-ecosystem-ci we can get a proper testing feedback loop, and the plugin being in a separate repo will help us avoid coupling and make it easier for other contributors to take ownership.
It would be interesting to know your thoughts on the overall performance-related direction (given this ticket is about performance) in this discussion |
@o-alexandrov answered there. We're going to provide guidance to use the current plugin for React or an SWC-based version when we release Vite 4. By using SWC, you are trading off flexibility (not being able to use babel plugins) and package size (~3x bigger) for HMR and cold start speed. The best option depends on the size of your project, and what libraries and patterns your project is using. |
Is SWC a must for what the plugin needs? HMR with just esbuild is still impossible, right? |
@silverwind, yes, it is out of the scope of esbuild at this point: evanw/esbuild#151 |
Description
Resolves #9429
Additional context
Development JSX transforms
esbuild supports dev-only JSX transforms (i.e.
jsxDev: true
) but this only works when using the automatic runtime. To preserve this functionality with the classic runtime,@babel/plugin-transform-react-jsx-self
and@babel/plugin-transform-react-jsx-source
will still be used in development when using the classic runtime.Automatic runtime in pre-compiled dependencies
This PR removes the existing
restoreJsx
functionality (intended to allow dependencies to use the automatic runtime) because 1) it already isn't working in the majority of cases and 2) conflicts with the use of esbuild to compile JSX. A detailed summary of the context around this was written by @cyco130 #9590 (comment)What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123
).