You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
React Compiler is a new compiler currently in Beta, that we've open sourced to get early feedback from the community. While it has been used in production at companies like Meta, rolling out the compiler to production for your app will depend on the health of your codebase and how well you’ve followed the [Rules of React](/reference/rules).
35
+
36
+
The latest Beta release can be found with the `@beta` tag, and daily experimental releases with `@experimental`.
37
+
</Note>
38
+
39
+
React Compiler is a new compiler that we've open sourced to get early feedback from the community. It is a build-time only tool that automatically optimizes your React app. It works with plain JavaScript, and understands the [Rules of React](/reference/rules), so you don't need to rewrite any code to use it.
40
+
41
+
The compiler also includes an [eslint plugin](#installing-eslint-plugin-react-compiler) that surfaces the analysis from the compiler right in your editor. **We strongly recommend everyone use the linter today.** The linter does not require that you have the compiler installed, so you can use it even if you are not ready to try out the compiler.
42
+
43
+
The compiler is currently released as `beta`, and is available to try out on React 17+ apps and libraries. To install the Beta:
请注意,编译器仍处于实验阶段,存在许多不完善之处。虽然它已经在 Meta 等公司的生产环境中使用过,但将编译器应用于你的应用程序生产环境将取决于你的代码库的健康状况以及你是否遵循了 [React的规则](/reference/rules)。
140
+
=======
141
+
### Should I try out the compiler? {/*should-i-try-out-the-compiler*/}
142
+
143
+
Please note that the compiler is still in Beta and has many rough edges. While it has been used in production at companies like Meta, rolling out the compiler to production for your app will depend on the health of your codebase and how well you've followed the [Rules of React](/reference/rules).
@@ -191,17 +227,59 @@ export default function App() {
191
227
```
192
228
193
229
当你对编译器的推出更有信心时,你也可以将覆盖范围扩展到其他目录,并逐渐将其推出到整个应用程序。
230
+
=======
231
+
When you have more confidence with rolling out the compiler, you can expand coverage to other directories as well and slowly roll it out to your whole app.
232
+
>>>>>>> 9467bc58868e66c53ca9385c8531dcf7b02178c2
194
233
195
234
#### 新项目 {/*new-projects*/}
196
235
197
236
如果你正在启动一个新项目,你可以在整个代码库上启用编译器,这是默认行为。
198
237
238
+
<<<<<<< HEAD
199
239
## 用法 {/*installation*/}
240
+
=======
241
+
### Using React Compiler with React 17 or 18 {/*using-react-compiler-with-react-17-or-18*/}
242
+
243
+
React Compiler works best with React 19 RC. If you are unable to upgrade, you can install the extra `react-compiler-runtime` package which will allow the compiled code to run on versions prior to 19. However, note that the minimum supported version is 17.
244
+
245
+
<TerminalBlock>
246
+
npm install react-compiler-runtime@beta
247
+
</TerminalBlock>
248
+
249
+
You should also add the correct `target` to your compiler config, where `target` is the major version of React you are targeting:
### Using the compiler on libraries {/*using-the-compiler-on-libraries*/}
267
+
268
+
React Compiler can also be used to compile libraries. Because React Compiler needs to run on the original source code prior to any code transformations, it is not possible for an application's build pipeline to compile the libraries they use. Hence, our recommendation is for library maintainers to independently compile and test their libraries with the compiler, and ship compiled code to npm.
269
+
270
+
Because your code is pre-compiled, users of your library will not need to have the compiler enabled in order to benefit from the automatic memoization applied to your library. If your library targets apps not yet on React 19, specify a minimum [`target` and add `react-compiler-runtime` as a direct dependency](#using-react-compiler-with-react-17-or-18). The runtime package will use the correct implementation of APIs depending on the application's version, and polyfill the missing APIs if necessary.
271
+
272
+
Library code can often require more complex patterns and usage of escape hatches. For this reason, we recommend ensuring that you have sufficient testing in order to identify any issues that might arise from using the compiler on your library. If you identify any issues, you can always opt-out the specific components or hooks with the [`'use no memo'` directive](#something-is-not-working-after-compilation).
273
+
274
+
Similarly to apps, it is not necessary to fully compile 100% of your components or hooks to see benefits in your library. A good starting point might be to identify the most performance sensitive parts of your library and ensuring that they don't break the [Rules of React](/reference/rules), which you can use `eslint-plugin-react-compiler` to identify.
2. Tests that nullable/optional values and properties are defined before accessing them (for example, by enabling [`strictNullChecks`](https://www.typescriptlang.org/tsconfig/#strictNullChecks) if using TypeScript), i.e., `if (object.nullableProperty) { object.nullableProperty.foo }` or with optional-chaining `object.nullableProperty?.foo`.
495
+
3. Follows the [Rules of React](https://react.dev/reference/rules).
496
+
497
+
React Compiler can verify many of the Rules of React statically, and will safely skip compilation when it detects an error. To see the errors we recommend also installing [eslint-plugin-react-compiler](https://www.npmjs.com/package/eslint-plugin-react-compiler).
0 commit comments