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 automatic JSX runtime and configuration via tsconfig.json #6501

Merged
merged 8 commits into from
Jun 26, 2021

Conversation

devongovett
Copy link
Member

Fixes #6389. Fixes #4622. Fixes #3287. Fixes #614. Closes T-1038.

This adds support for the new automatic JSX runtime added in React 17. This is automatically enabled when the version of React the app depends on is >= 17.0.0.

Additionally, this adds support for reading several options from tsconfig.json.

  • jsx - Enable JSX even when an auto-detected library isn't installed. Can also be used to enable the automatic JSX runtime if set to react-jsx.
  • jsxImportSource - The import source for the automatic JSX runtime (e.g. react or preact)
  • jsxFactory - The pragma for the classic JSX transform.
  • jsxFragmentFactory - The fragment factory for the classic JSX transform.
  • experimentalDecorators enables support for legacy decorators, as used by TypeScript.

@height
Copy link

height bot commented Jun 22, 2021

This pull request has been linked to and will mark 1 task as "Done" when merged:

💡Tip: You can link multiple Height tasks to a pull request.

@parcel-benchmark
Copy link

parcel-benchmark commented Jun 22, 2021

Benchmark Results

Kitchen Sink 🚨

Timings

Description Time Difference
Cold FAILED -0.00ms
Cached FAILED -0.00ms

Cold Bundles

No bundles found, this is probably a failed build...

Cached Bundles

No bundles found, this is probably a failed build...

React HackerNews ✅

Timings

Description Time Difference
Cold 10.22s +12.00ms
Cached 468.00ms +4.00ms

Cold Bundles

No bundle changes detected.

Cached Bundles

Bundle Size Difference Time Difference
dist/logo.1e014c76.png 274.00b +0.00b 287.00ms -19.00ms 🚀

AtlasKit Editor 🚨

Timings

Description Time Difference
Cold FAILED -0.00ms
Cached FAILED -0.00ms

Cold Bundles

No bundles found, this is probably a failed build...

Cached Bundles

No bundles found, this is probably a failed build...

Three.js ✅

Timings

Description Time Difference
Cold 7.15s +68.00ms
Cached 402.00ms -5.00ms

Cold Bundles

No bundle changes detected.

Cached Bundles

No bundle changes detected.

Click here to view a detailed benchmark overview.

@mischnic
Copy link
Member

Should it also look at jsconfig.json? Might be weird to have to add a tsconfig file to change React settings even if you're not using Typescript

@devongovett
Copy link
Member Author

I wondered the same. I couldn't find definitive information about it though. Does jsconfig.json support compilerOptions even though it isn't being compiled by TSC presumably?

@mischnic
Copy link
Member

mischnic commented Jun 22, 2021

This makes it sound like it is:

jsconfig.json is a descendant of tsconfig.json, which is a configuration file for TypeScript. jsconfig.json is tsconfig.json with "allowJs" attribute set to true.
(https://code.visualstudio.com/docs/languages/jsconfig)

And there is an example with compilerOptions.target on that page

@devongovett
Copy link
Member Author

Hmm ok. Also should tsconfig only apply to .ts and .tsx files or also to .js files in the same project? And same for the inverse? Or should they just be treated as interchangeable?

@mischnic
Copy link
Member

I would say prefer tsconfig over jsconfig in getConfigFrom, but I don't know how tsc/VS Code behave.

@mischnic
Copy link
Member

This is automatically enabled when the version of React the app depends on is >= 17.0.0.

Preact >=10.5.0 support the automatic JSX runtime: https://github.com/preactjs/preact/releases/tag/10.5.0

@devongovett
Copy link
Member Author

Found this "bug" about jsconfig.json not being picked up when a tsconfig.json is present, and it claims it's by design so we'll follow it. microsoft/TypeScript#15869

@devongovett devongovett merged commit 28eb380 into v2 Jun 26, 2021
@devongovett devongovett deleted the jsx-config branch June 26, 2021 05:37
@Rechdan
Copy link

Rechdan commented Jun 28, 2021

We can't don't import React when on v17?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants