|
| 1 | +--- |
| 2 | +title: "React Compiler RC" |
| 3 | +author: Lauren Tan and Mofei Zhang |
| 4 | +date: 2025/04/21 |
| 5 | +description: We are releasing the compiler's first Release Candidate (RC) today. |
| 6 | + |
| 7 | +--- |
| 8 | + |
| 9 | +April 21, 2025 by [Lauren Tan](https://x.com/potetotes) and [Mofei Zhang](https://x.com/zmofei). |
| 10 | + |
| 11 | +--- |
| 12 | + |
| 13 | +<Intro> |
| 14 | + |
| 15 | +The React team is excited to share new updates: |
| 16 | + |
| 17 | +</Intro> |
| 18 | + |
| 19 | +1. We're publishing React Compiler RC today, in preparation of the compiler's stable release. |
| 20 | +2. We're simplifying your eslint setup by merging `eslint-plugin-react-compiler` into `eslint-plugin-react-hooks`. |
| 21 | +3. We're working with the swc and oxc teams to add plugins to allow for Babel-free build pipelines. |
| 22 | + |
| 23 | +--- |
| 24 | + |
| 25 | +[React Compiler](https://react.dev/learn/react-compiler) is a build-time tool that optimizes your React app through automatic memoization. Last year, we published React Compiler’s [first beta](https://react.dev/blog/2024/10/21/react-compiler-beta-release) and received lots of great feedback and contributions. We’re excited about the wins we’ve seen from folks adopting the compiler (see case studies from [Sanity Studio](https://github.com/reactwg/react-compiler/discussions/33) and [Wakelet](https://github.com/reactwg/react-compiler/discussions/52)) and are working towards a stable release. |
| 26 | + |
| 27 | +We are releasing the compiler's first Release Candidate (RC) today. The RC is intended to be a stable and near-final version of the compiler, and safe to use in production for all React users. |
| 28 | + |
| 29 | +## Use React Compiler RC today {/*use-react-compiler-rc-today*/} |
| 30 | +To install the RC: |
| 31 | + |
| 32 | +npm |
| 33 | +<TerminalBlock> |
| 34 | +{`npm install --save-dev --save-exact babel-plugin-react-compiler@rc`} |
| 35 | +</TerminalBlock> |
| 36 | + |
| 37 | +pnpm |
| 38 | +<TerminalBlock> |
| 39 | +{`pnpm add --save-dev --save-exact babel-plugin-react-compiler@rc`} |
| 40 | +</TerminalBlock> |
| 41 | + |
| 42 | +yarn |
| 43 | +<TerminalBlock> |
| 44 | +{`yarn add --dev --exact babel-plugin-react-compiler@rc`} |
| 45 | +</TerminalBlock> |
| 46 | + |
| 47 | +As part of the RC, we've been making React Compiler easier to add to your projects and added optimizations to how the compiler generates memoization. React Complier now supports optional chains and array indices as dependencies. We're exploring how to infer even more dependencies like equality checks and string interpolation. These improvements ultimately result in fewer re-renders and more responsive UIs. |
| 48 | + |
| 49 | +We have also heard from the community that the ref-in-render validation sometimes has false positives. Since as a general philosophy we want you to be able to fully trust in the compiler's error messages and hints, we are turning it off by default for now. We will keep working to improve this validation, and we will re-enable it in a follow up release. |
| 50 | + |
| 51 | +You can find more details on using the Compiler in [our docs](https://react.dev/learn/react-compiler). |
| 52 | + |
| 53 | +### Backwards Compatibility {/*backwards-compatibility*/} |
| 54 | +As noted in the Beta announcement, React Compiler is compatible with React 17 and up. If you are not yet on React 19, you can use React Compiler by specifying a minimum target in your compiler config, and adding `react-compiler-runtime` as a dependency. You can find docs on this [here](https://react.dev/learn/react-compiler#using-react-compiler-with-react-17-or-18). |
| 55 | + |
| 56 | +## Migrating from eslint-plugin-react-compiler to eslint-plugin-react-hooks {/*migrating-from-eslint-plugin-react-compiler-to-eslint-plugin-react-hooks*/} |
| 57 | +To install eslint-plugin-react-hooks: |
| 58 | + |
| 59 | +npm |
| 60 | +<TerminalBlock> |
| 61 | +{`npm install --save-dev eslint-plugin-react-hooks@^6.0.0`} |
| 62 | +</TerminalBlock> |
| 63 | + |
| 64 | +pnpm |
| 65 | +<TerminalBlock> |
| 66 | +{`pnpm add --save-dev eslint-plugin-react-hooks@^6.0.0`} |
| 67 | +</TerminalBlock> |
| 68 | + |
| 69 | +yarn |
| 70 | +<TerminalBlock> |
| 71 | +{`yarn add --dev eslint-plugin-react-hooks@^6.0.0`} |
| 72 | +</TerminalBlock> |
| 73 | + |
| 74 | +`eslint-plugin-react-hooks` 5.2.0 has been ported to TypeScript, which allowed us to improve the type-safety of the plugin. In the 6.0.0 release of the ESLint plugin, the compiler lint rule has now been merged in. If you were previously using `eslint-plugin-react-compiler`, this means you can now use a single ESLint plugin in your codebase. Many thanks to [@michaelfaith](https://bsky.app/profile/michael.faith) for contributing to this improvement! |
| 75 | + |
| 76 | +```js |
| 77 | +// eslint.config.js |
| 78 | +import*asreactHooksfrom'eslint-plugin-react-hooks'; |
| 79 | + |
| 80 | +exportdefault [ |
| 81 | +// Flat Config (eslint 9+) |
| 82 | +reactHooks.configs.recommended, |
| 83 | + |
| 84 | +// Legacy Config |
| 85 | +reactHooks.configs['recommended-latest'] |
| 86 | +]; |
| 87 | +``` |
| 88 | + |
| 89 | +The linter does not require the compiler to be installed, so there's no risk in upgrading eslint-plugin-react-hooks. We recommend everyone upgrade today. |
| 90 | + |
| 91 | +## swc and oxc support (experimental) {/*swc-and-oxc-support-experimental*/} |
| 92 | +We have also been collaborating with Kang Dongyoong ([@kdy1dev](https://x.com/kdy1dev)) from the [swc](https://swc.rs/) team on adding support for React Compiler as an swc plugin. As part of the RC release, you can integrate the compiler into your [Next.js app with swc](https://nextjs.org/docs/app/api-reference/config/next-config-js/reactCompiler) instead of babel. We are also working with the [oxc](https://oxc.rs/) team to [add support for the compiler](https://github.com/oxc-project/oxc/issues/10048), which should allow more people to use the compiler if they have already migrated off of Babel. |
| 93 | + |
| 94 | +Next.js users can upgrade to [15.3.1](https://github.com/vercel/next.js/releases/tag/v15.3.1) or greater to try this out. If you have already enabled the compiler in your Next.js's config, swc support will be enabled automatically. |
| 95 | + |
| 96 | +Vite users can continue to use [vite-plugin-react](https://github.com/vitejs/vite-plugin-react) to enable the compiler, by adding it as a [Babel plugin](https://react.dev/learn/react-compiler#usage-with-vite). Once [rolldown](https://github.com/rolldown/rolldown) is officially released and supported in Vite and oxc support is added for React Compiler, we'll update the docs with information on how to migrate. |
| 97 | + |
| 98 | +## Upgrading React Compiler {/*upgrading-react-compiler*/} |
| 99 | +React Compiler works best when the auto-memoization applied is strictly for performance. Future versions of the compiler may change how memoization is applied, for example it could become more granular and precise. |
| 100 | + |
| 101 | +However, because product code may sometimes break the [rules of React](https://react.dev/reference/rules) in ways that aren't always statically detectable in JavaScript, changing memoization can occasionally have unexpected results. For example, a previously memoized value might be used as a dependency for a useEffect somewhere in the component tree. Changing how or whether this value is memoized can cause over or under-firing of that useEffect. While we encourage [useEffect only for synchronization](https://react.dev/learn/synchronizing-with-effects), your codebase may have useEffects that cover other use-cases. For example you may have an effect that runs in response to some value changing (breaks the rules of React). |
| 102 | + |
| 103 | +In other words, changing memoization may under rare circumstances cause unexpected behavior. For this reason, we recommend following the Rules of React and employing continuous end-to-end testing of your app so you can upgrade the compiler with confidence and identify any rules of React violations that might cause issues. |
| 104 | + |
| 105 | +If you don't have good test coverage, we recommend pinning the compiler to an exact version (eg `19.0.0`) rather than a SemVer range (eg `^19.0.0`). You can do this by passing the `--save-exact` (npm/pnpm) or `--exact` flags (yarn) when upgrading the compiler. You should then do any upgrades of the compiler manually, taking care to check that your app still works as expected. |
| 106 | + |
| 107 | +## Roadmap to Stable {/*roadmap-to-stable*/} |
| 108 | +*This is not a final roadmap, and is subject to change.* |
| 109 | + |
| 110 | +After a period of final feedback from the community on the RC, we plan on a Stable Release for the compiler. |
| 111 | + |
| 112 | +* ✅ Experimental: Released at React Conf 2024, primarily for feedback from application developers. |
| 113 | +* ✅ Public Beta: Available today, for feedback from library authors. |
| 114 | +* ✅ Release Candidate (RC): React Compiler works for the majority of rule-following apps and libraries without issue. |
| 115 | +* General Availability: After final feedback period from the community. |
| 116 | + |
| 117 | +Post-Stable, we plan to add more compiler optimizations and improvements. This includes both continual improvements to automatic memoization, and new optimizations altogether, with minimal to no change of product code. Each upgrade will continue to improve performance and add better handling of diverse JavaScript and React patterns. |
| 118 | + |
| 119 | +## Feedback {/*feedback*/} |
| 120 | +During the RC period, we encourage all React users to try the compiler and provide feedback in the React repo. Please [open an issue](https://github.com/facebook/react/issues) if you encounter any bugs or unexpected behavior. If you have a general question or suggestion, please post them in the [React Compiler Working Group](https://github.com/reactwg/react-compiler/discussions). |
| 121 | + |
| 122 | +--- |
| 123 | + |
| 124 | +Thanks to [Joe Savona](https://x.com/en_JS), [Jason Bonta](https://twitter.com/someextent), [Jimmy Lai](https://x.com/feedthejim), and [Kang Dongyoon](https://x.com/kdy1dev) (@kdy1dev) for reviewing and editing this post. |
0 commit comments