Skip to content
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

Support jsx automatic runtime #712

Closed
re-thc opened this issue Aug 16, 2020 · 9 comments
Closed

Support jsx automatic runtime #712

re-thc opened this issue Aug 16, 2020 · 9 comments
Labels
enhancement New feature or request

Comments

@re-thc
Copy link

re-thc commented Aug 16, 2020

React 17 will be adding jsx automatic runtime. It's now available in the latest release candidate.

More info here.

Can vite support this? i.e. react/jsx-runtime and react/jsx-dev-runtime

Thanks!

@zhangyuang
Copy link
Contributor

not yet. jsx in react use esbuild default that React.createElement。maybe add it to the configuration later。

const JsxPresets: Record<
  string,
  Pick<TransformOptions, 'jsxFactory' | 'jsxFragment'>
> = {
  vue: { jsxFactory: 'jsx', jsxFragment: 'Fragment' },
  preact: { jsxFactory: 'h', jsxFragment: 'Fragment' },
  react: {} // use esbuild default
}

@intrnl
Copy link
Contributor

intrnl commented Aug 16, 2020

This will have to depend on esbuild itself.

@underfin
Copy link
Member

I close this and wait evanw/esbuild#334 resloved, we will support it.

@re-thc
Copy link
Author

re-thc commented Sep 15, 2020

esbuild has stated they are not directly supporting it.

@intrnl
Copy link
Contributor

intrnl commented Sep 15, 2020

I think it'd be best to wait until this comment gets an answer.

We could probably try appending the imports ourselves, not sure about identifier conflicts though.

@aleclarson aleclarson reopened this Nov 28, 2020
@aleclarson aleclarson added the enhancement New feature or request label Nov 28, 2020
@yyx990803
Copy link
Member

@aleclarson
Copy link
Member

@yyx990803 New update on this: evanw/esbuild#334 (comment)

esbuild won't support this OOTB, so Vite needs to maintain an esbuild plugin.

@aleclarson aleclarson reopened this Jan 14, 2021
@yyx990803
Copy link
Member

That plugin is only for bundling with esbuild. Vite only uses esbuild to transpile J/TSX, not for bundling. So if esbuild is not going to natively support React 17 jsx transforms, people who want React 17 transform in Vite will need to disable esbuild in Vite and use a separate Vite plugin to transpile JSX files, similar to @vitejs/plugin-vue-jsx.

Alternatively, use esbuild.jsxInject option (https://vitejs.dev/config/#esbuild) for now, since React 17 still supports the old transform, most people are just looking to avoid having to manually import React for JSX.

@aleclarson
Copy link
Member

I've published v1 of vite-react-jsx which solves this issue.

https://github.com/alloc/vite-react-jsx

@github-actions github-actions bot locked and limited conversation to collaborators Jul 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

6 participants