Skip to content

Conversation

ArnaudBarre
Copy link
Member

@ArnaudBarre ArnaudBarre commented Aug 30, 2025

Alternative to #20702 and vitejs/vite-plugin-react#799 from @poteto which make it easier to keep the template in sync

close #20702, close vitejs/vite-plugin-react#799

@ArnaudBarre ArnaudBarre self-assigned this Aug 30, 2025
@ArnaudBarre ArnaudBarre changed the title feat(create-vite): support react compiler feat(create-vite): support React Compiler Aug 30, 2025
@poteto
Copy link

poteto commented Aug 30, 2025

oh this is better, thank you!

const asObject = JSON.parse(content)
const devDepsEntries = Object.entries(asObject.devDependencies)
devDepsEntries.push([
'babel-plugin-react-compiler',
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one thing that's missing is also using [email protected]. Version 6 will include compiler diagnostics as part of the plugin by default.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's quite a bump in dependencies. plugin-proposal-private-methods is deprecated, and I'm surprise of the need for zod in a linter plugin.
Is the hermes parser necessary given that the build will use the babel parser?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not as much an issue, but are you open to switching to ESM for the next major? ESLint v9 is now quite the norm and fully support ESM. I can make a PR to either reduce the dependency or switch to ESM if you think there is a chance it lands

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ArnaudBarre yes, the eslint plugin now bundles the compiler as well since it can be used standalone. That means a few extra dependencies are needed. Is that blocking anything?

As for ESM I think that will require a larger discussion with the rest of the React team.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The react compiler only requires @babel/types as a dependency so I'm still unsure what are the need for all these extra dependencies. It adds extra install size (zod 3 & hermes-parser probably not be present for a number of apps) and extra attack surface for package hijacking like what happen yesterday.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ArnaudBarre we inline most dependencies in babel-plugin-react-compiler which is why it only appears to depend on @babel/types (this is mostly a consequence of some Meta-internal infra quirks). For eslint-plugin-react-hooks we didn't, but I can inline as well if it's a hard requirement to get this shipped. Effectively the eslint plugin now includes the entire compiler as it needs to be able to be used standalone, hence the zod (validating compiler configs) and hermes-parser (parsing both Flow and JavaScript/TypeScript into a Babel compatible AST) dependencies.

Copy link
Member Author

@ArnaudBarre ArnaudBarre Sep 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's needed to depend on it, it's not directly used: https://github.com/search?q=repo%3Afacebook%2Freact%20path%3A%2F%5Epackages%5C%2Feslint-plugin-react-hooks%5C%2F%2F%20zod&type=code

Instead I think the eslint plugin should make babel-plugin-react-compiler a peer-dependency? (maybe optional if it's not required for some rules and lazy loaded for others)

Edit: Ok I see that the plugin rebundle the compiler, why not depend on it (to avoid having it twice). It would also make the runtime & lint rules in sync for users?

Also the current published version as two 2MB files, is it possible to only publish the development version?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@poteto is there somewhere we could discuss this stuff outside of this PR too?

the modern approach to custom parsers in ESLint is to provide a language implementation, like how @eslint/json works. the hooks plugin shouldn't really need to care about parsing at all, since a language should've already been setup to parse the various formats correctly (in this case, flow and a custom JS parse with the compiler plugin).

this is a fairly modern part of ESLint though so makes sense the hooks plugin doesn't do it this way yet. so maybe we should track it in an issue somewhere?

@sapphi-red sapphi-red added the feat: create-vite create-vite package label Aug 31, 2025
@sapphi-red
Copy link
Member

I think there're two other ways:

  1. add react compiler by default
  2. add a comment in vite config so that users can easily add react compiler
  3. (the current way) add a new temlpate

Do you have any thoughts about the other ways?

@ArnaudBarre
Copy link
Member Author

The compiler by default would mean we don't run OXC by default. Which can impact the boot time of the starter (I didn't yet benchmark it). This would also mean keeping Babel by default. But given what is the next version of eslint-plugin-react-hooks, we woud need to revisit eslint by default if our goal is to have a light template

I think the benefit of having a template with already the compiler setup is to make it easy to quickly try a pattern on a empty app. That said, the way the template is setup forbid the usage via stackblitz which is the easiest way to create repro...

@github-project-automation github-project-automation bot moved this to Discussing in Team Board Sep 16, 2025
Copy link
Member

@bluwy bluwy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm happy with the PR (besides the small typo comment)

@sapphi-red sapphi-red moved this from Discussing to Approved in Team Board Sep 17, 2025
@ArnaudBarre ArnaudBarre force-pushed the arnaud/create-vite-react-compiler branch from bab7fb0 to a86ad0b Compare September 22, 2025 22:19
@ArnaudBarre ArnaudBarre requested review from bluwy and sapphi-red and removed request for sapphi-red September 22, 2025 22:19
@ArnaudBarre
Copy link
Member Author

@sapphi-red @bluwy I added a small note on performances, but not sure of the wording, open to suggestions

Copy link
Member

@bluwy bluwy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm ok with the current wording 👍

Copy link
Member

@sapphi-red sapphi-red left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@sapphi-red sapphi-red merged commit 052aa88 into main Sep 23, 2025
20 checks passed
@sapphi-red sapphi-red deleted the arnaud/create-vite-react-compiler branch September 23, 2025 02:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feat: create-vite create-vite package

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

5 participants