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

Use automatic react runtime for v18.0.0 #6948

Closed
wants to merge 1 commit into from

Conversation

alexeyraspopov
Copy link

↪️ Pull Request

When using react@next and react-dom@next, NPM installs v18.0.0-alpha-XXXXXXX. Parcel uses >= 17.0.0 to determine whether to use automatic runtime or React.createElement. The check fails for v18.x probably because of semver: >=17.0.0 does not go beyond the major release.

🚨 Test instructions

Using a fresh nightly build parcel@^2.0.0-nightly.838 with react@^18.0.0-alpha-a8cabb564-20210915 (and similar react-dom, or simply react@next), writing any JSX without import React from 'react' throws an error React is not defined in browser.

✔️ PR Todo

  • Added/updated unit tests for this change
  • Filled out test instructions (In case there aren't any unit tests)
  • Included links to related issues/PRs

@height
Copy link

height bot commented Sep 16, 2021

Link Height tasks by mentioning a task ID in the pull request title or description, commit messages, or comments.

💡Tip: You can also use "Close T-X" to automatically close a task when the pull request is merged.

@mtgto
Copy link

mtgto commented Oct 2, 2021

The check fails for v18.x probably because of semver: >=17.0.0 does not go beyond the major release.

It seems to be a bit wrong. The problem is semver.satisfies returns false when target version is prerelease.

I test with RunKit.
https://npm.runkit.com/semver

console.log(semver.satisfies('18.0.0', '>= 17.0.0')); // true
console.log(semver.satisfies('18.0.0-alpha-a8cabb564-20210915', '>= 17.0.0')); // false

BTW, I suggest to use coercion of semver to compare versions including prelease libraries.

console.log(semver.valid(semver.coerce('18.0.0-alpha-a8cabb564-20210915'))); // "18.0.0"
console.log(semver.satisfies(semver.valid(semver.coerce('18.0.0-alpha-a8cabb564-20210915')), '>= 17.0.0')); // true

@alexeyraspopov
Copy link
Author

@mtgto, I do agree coerce() makes sense. I guess the issue will be resolved once v18 is released, so there will be no need to update the version range, but every following alpha/beta/rc/nightly will keep breaking the condition

@mischnic
Copy link
Member

This looks like a cleaner solution:

require("semver").satisfies("18.0.0-rc.0-next-13036bfbc-20220121", ">= 17.0.0", {includePrerelease: true})
===
true

@alexeyraspopov Could you fix that?

@gaearon
Copy link

gaearon commented Jan 22, 2022

The approach doesn’t seem ideal because it won’t work for 0.0.0 versions tagged as @experimental. I’d suggest checking for the presence of /jsx-runtime entry point in the package.

@mischnic
Copy link
Member

We don't really want to do a path resolution for every single asset to determine this. I think it's safe to assume that using an experimental React version means that it's a recent one which supports the automatic runtime (and if not, these very few projects could still use the manualy jsconfig setting). So the check should be something like
>=17 (including prereleases) OR 0.0.0 (including prereleases)

@gaearon
Copy link

gaearon commented Jan 25, 2022

Fair.

@gaearon
Copy link

gaearon commented Jan 25, 2022

for every single asset

(I don't understand this part but your approach sounds good to me too.)

@devongovett
Copy link
Member

Opened a new PR to implement the above suggestion: #7642

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

Successfully merging this pull request may close these issues.

JSX automatic transform doesn't get used for 18+ prereleases
5 participants