[Typo]: The alternative way to configure react compiler with vitejs doesn't work
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 11.8k
- Forks
- 7.9k
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 11
Description
Summary
The alternative way to configure react-compiler with Vitejs, which is to declare the Babel configuration separately, doesn't actually work.
Page
https://react.dev/learn/react-compiler/installation#vite
Details
Note that I'm talking about a TypeScript scenario.
I figure this is because of the default filter parameter which is specfieid to be jsx (you can find it here).
For the fix, it seems the babel config provided for react-router case works well with vite-plugin-react. so maybe we can use that, it would look something like this:
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import babel from 'vite-plugin-babel';
const ReactCompilerConfig = { /* ... */ };
export default defineConfig({
plugins: [
react(),
babel({
filter: /\.[jt]sx?$/,
babelConfig: {
presets: ["@babel/preset-typescript"],
plugins: [
["babel-plugin-react-compiler", ReactCompilerConfig],
],
},
}),
],
});
Also, maybe it's not a good idea to talk about it here, but I suggest to also have a guide for how the configuration should look like for a vite user who uses JavaScript (jsx) instead of TypeScript because apparently removing the TypeScript babel preset doesn't turn it into a JavaScript configuration; it requires more adjustments.
so maybe considering all of this, we are better off just removing the alternative, since it causes more problems than it solves 😅
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at react.dev/learn/react-compiler/installation#vite and compare the alternative Babel configuration with the React Router example at #usage-with-react-router. Verify the TypeScript and JavaScript/Vite cases, then update the page so the documented setup works or remove the alternative; confirm the final instructions and examples are consistent.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, react, typescript, vite
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100