Skip to content

Commit 786de5d

Browse files
committed
docs(en): merging all conflicts
2 parents 6f1ae3b + 740016e commit 786de5d

File tree

10 files changed

+219
-11
lines changed

10 files changed

+219
-11
lines changed

next-env.d.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/// <reference types="next" />
22
/// <reference types="next/image-types/global" />
3-
/// <reference types="next/navigation-types/compat/navigation" />
43

54
// NOTE: This file should not be edited
6-
// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.
5+
// see https://nextjs.org/docs/pages/api-reference/config/typescript for more information.

src/content/blog/2024/10/21/react-compiler-beta-release.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ October 21, 2024 by [Lauren Tan](https://twitter.com/potetotes).
1010

1111
---
1212

13+
<Note>
14+
15+
### React Compiler is now in RC! {/*react-compiler-is-now-in-rc*/}
16+
17+
Please see the [RC blog post](/blog/2025/04/21/react-compiler-rc) for details.
18+
19+
</Note>
20+
1321
<Intro>
1422

1523
React 团队很高兴分享新的内容:
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
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 merging `eslint-plugin-react-compiler` into `eslint-plugin-react-hooks`.
21+
3. We've added support for swc and are working with oxc to support Babel-free builds.
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 try out in production.
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+
## Feedback {/*feedback*/}
54+
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).
55+
56+
## Backwards Compatibility {/*backwards-compatibility*/}
57+
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).
58+
59+
## Migrating from eslint-plugin-react-compiler to eslint-plugin-react-hooks {/*migrating-from-eslint-plugin-react-compiler-to-eslint-plugin-react-hooks*/}
60+
If you have already installed eslint-plugin-react-compiler, you can now remove it and use `eslint-plugin-react-hooks@^6.0.0-rc.1`. Many thanks to [@michaelfaith](https://bsky.app/profile/michael.faith) for contributing to this improvement!
61+
62+
To install:
63+
64+
npm
65+
<TerminalBlock>
66+
{`npm install --save-dev eslint-plugin-react-hooks@^6.0.0-rc.1`}
67+
</TerminalBlock>
68+
69+
pnpm
70+
<TerminalBlock>
71+
{`pnpm add --save-dev eslint-plugin-react-hooks@^6.0.0-rc.1`}
72+
</TerminalBlock>
73+
74+
yarn
75+
<TerminalBlock>
76+
{`yarn add --dev eslint-plugin-react-hooks@^6.0.0-rc.1`}
77+
</TerminalBlock>
78+
79+
```js
80+
// eslint.config.js
81+
import * as reactHooks from 'eslint-plugin-react-hooks';
82+
83+
export default [
84+
// Flat Config (eslint 9+)
85+
reactHooks.configs.recommended,
86+
87+
// Legacy Config
88+
reactHooks.configs['recommended-latest']
89+
];
90+
```
91+
92+
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.
93+
94+
## swc support (experimental) {/*swc-support-experimental*/}
95+
React Compiler can be installed across [several build tools](/learn/react-compiler#installation) such as Babel, Vite, and Rsbuild.
96+
97+
In addition to those tools, we have been collaborating with Kang Dongyoong ([@kdy1dev](https://x.com/kdy1dev)) from the [swc](https://swc.rs/) team on adding additional support for React Compiler as an swc plugin. As part of the RC release, you can now 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.
98+
99+
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.
100+
101+
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). 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). 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.
102+
103+
## Upgrading React Compiler {/*upgrading-react-compiler*/}
104+
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.
105+
106+
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 such as effects that needs to only run in response to specific values changing.
107+
108+
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.
109+
110+
If you don't have good test coverage, we recommend pinning the compiler to an exact version (eg `19.1.0`) rather than a SemVer range (eg `^19.1.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.
111+
112+
## Roadmap to Stable {/*roadmap-to-stable*/}
113+
*This is not a final roadmap, and is subject to change.*
114+
115+
After a period of final feedback from the community on the RC, we plan on a Stable Release for the compiler.
116+
117+
* ✅ Experimental: Released at React Conf 2024, primarily for feedback from application developers.
118+
* ✅ Public Beta: Available today, for feedback from library authors.
119+
* ✅ Release Candidate (RC): React Compiler works for the majority of rule-following apps and libraries without issue.
120+
* General Availability: After final feedback period from the community.
121+
122+
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.
123+
124+
---
125+
126+
Thanks to [Joe Savona](https://x.com/en_JS), [Jason Bonta](https://x.com/someextent), [Jimmy Lai](https://x.com/feedthejim), and [Kang Dongyoon](https://x.com/kdy1dev) (@kdy1dev) for reviewing and editing this post.

src/content/blog/index.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,30 @@ title: React Blog
44

55
<Intro>
66

7+
<<<<<<< HEAD
78
这个博客是 React 团队更新的官方来源。任何重要的内容,包括发布说明或弃用通知,都会首先在这里发布。
9+
=======
10+
This blog is the official source for the updates from the React team. Anything important, including release notes or deprecation notices, will be posted here first.
11+
12+
You can also follow the [@react.dev](https://bsky.app/profile/react.dev) account on Bluesky, or [@reactjs](https://twitter.com/reactjs) account on Twitter, but you won’t miss anything essential if you only read this blog.
13+
>>>>>>> 740016e4dea7e518bd045309bc3e828cc2a787a4
814
915
你也可以在 Bluesky 上关注 [@react.dev](https://bsky.app/profile/react.dev),或者在 Twitter 上关注 [@reactjs](https://twitter.com/reactjs)。不过只要你阅读这个博客,就不会错过任何重要内容。
1016
</Intro>
1117

1218
<div className="sm:-mx-5 flex flex-col gap-5 mt-12">
1319

20+
<<<<<<< HEAD
1421
<BlogCard title="逐步淘汰 Create React App" date="February 13, 2025" url="/blog/2025/02/14/sunsetting-create-react-app">
22+
=======
23+
<BlogCard title="React Compiler RC" date="April 21, 2025" url="/blog/2025/04/21/react-compiler-rc">
24+
25+
We are releasing the compiler's first Release Candidate (RC) today.
26+
27+
</BlogCard>
28+
29+
<BlogCard title="Sunsetting Create React App" date="February 14, 2025" url="/blog/2025/02/14/sunsetting-create-react-app">
30+
>>>>>>> 740016e4dea7e518bd045309bc3e828cc2a787a4
1531
1632
今日起,我们将正式弃用 Create React App 作为新应用的推荐工具,并建议现有应用迁移至框架或构建工具(如 Vite、Parcel 和 RSBuild)。我们还提供了相关文档用于这些情况:你的项目不适合使用框架、你想要构建自己的框架,或者只是想通过从零开始构建一个 React 应用来了解 React 的工作原理等等……
1733

src/content/learn/creating-a-react-app.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,11 @@ Next.js 的 App Router 还集成了 [使用 Suspense 的数据获取](/blog/2022
106106

107107
从零开始可以给你更多的灵活性,但同时也要求你必须自己选择用于路由、数据获取以及其他常见使用模式的工具。这更像自己构建一个框架,而不是使用一个已经存在的框架。[我们推荐的框架](#full-stack-frameworks) 为这些问题提供了内置的解决方案。
108108

109+
<<<<<<< HEAD
109110
如果你想构建自己的解决方案,请参阅我们的 [从零构建一个 React 应用](/learn/build-a-react-app-from-scratch) 指南,该指南提供了如何使用 [Vite](https://vite.dev/)[Parcel](https://parceljs.org/),或 [RSbuild](https://rsbuild.dev/) 等构建工具设置新 React 项目的说明。
111+
=======
112+
If you want to build your own solutions, see our guide to [build a React app from Scratch](/learn/build-a-react-app-from-scratch) for instructions on how to set up a new React project starting with a build tool like [Vite](https://vite.dev/), [Parcel](https://parceljs.org/), or [RSbuild](https://rsbuild.dev/).
113+
>>>>>>> 740016e4dea7e518bd045309bc3e828cc2a787a4
110114
111115
-----
112116

src/content/learn/react-compiler.md

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@ title: React Compiler
66
本页面将为你介绍新的 React Compiler,以及如何成功试用。
77
</Intro>
88

9+
<<<<<<< HEAD
910
<Wip>
1011
这些文档仍在不断完善中。更多文档可在 [React Compiler 工作组代码库](https://github.com/reactwg/react-compiler/discussions) 中找到,并在这些文档更加稳定时被整合进来。
1112
</Wip>
1213

14+
=======
15+
>>>>>>> 740016e4dea7e518bd045309bc3e828cc2a787a4
1316
<YouWillLearn>
1417
1518
* 开始使用 React Compiler
@@ -19,6 +22,7 @@ title: React Compiler
1922
</YouWillLearn>
2023

2124
<Note>
25+
<<<<<<< HEAD
2226
React Compiler 是一个处于 Beta 阶段的新的编译器,我们将其开源以获取社区的早期反馈。虽然Meta 等公司已经在生产中使用它,但是能否在你的应用程序中使用它取决于代码库的健康状态以及你遵守 [React 规则](/reference/rules) 的程度。
2327

2428
最新的 Beta 版本发布于 `@beta` 标签,每日实验版本发布于 `@experimental` 标签。
@@ -30,15 +34,27 @@ React Compiler 是一个新编译器,我们将其开源以获取社区的早
3034
编译器还包括一个 [ESLint 插件](#installing-eslint-plugin-react-compiler),可以在你的编辑器中直接显示编译器的分析结果。**我们强烈建议大家使用 linter。** 不过 linter 并不需要安装编译器,因此即使你还没有准备好尝试编译器也可以使用它。
3135

3236
编译器目前处于 `beta` 阶段,并且可以在 React 17+ 应用程序和库上使用。安装方式如下:
37+
=======
38+
React Compiler is a new compiler currently in RC, that we've open sourced to get feedback from the community. We now recommend everyone to try the compiler and provide feedback.
39+
40+
The latest RC release can be found with the `@rc` tag, and daily experimental releases with `@experimental`.
41+
</Note>
42+
43+
React Compiler is a new compiler that we've open sourced to get 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.
44+
45+
eslint-plugin-react-hooks also includes an [ESLint rule](#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.
46+
47+
The compiler is currently released as `rc`, and is available to try out on React 17+ apps and libraries. To install the RC:
48+
>>>>>>> 740016e4dea7e518bd045309bc3e828cc2a787a4
3349
3450
<TerminalBlock>
35-
npm install -D babel-plugin-react-compiler@beta eslint-plugin-react-compiler@beta
51+
{`npm install -D babel-plugin-react-compiler@rc eslint-plugin-react-hooks@^6.0.0-rc.1`}
3652
</TerminalBlock>
3753

3854
或者使用 Yarn:
3955

4056
<TerminalBlock>
41-
yarn add -D babel-plugin-react-compiler@beta eslint-plugin-react-compiler@beta
57+
{`yarn add -D babel-plugin-react-compiler@rc eslint-plugin-react-hooks@^6.0.0-rc.1`}
4258
</TerminalBlock>
4359

4460
如果你还没有使用 React 19,请参考 [此内容](#using-react-compiler-with-react-17-or-18) 以获得进一步说明。
@@ -117,22 +133,33 @@ function TableContainer({ items }) {
117133

118134
### 我应该尝试一下编译器吗? {/*should-i-try-out-the-compiler*/}
119135

136+
<<<<<<< HEAD
120137
请注意,编译器仍处于 Beta 阶段,存在许多不完善之处。虽然它已经在 Meta 等公司的生产环境中使用过,但将编译器应用于你的应用程序生产环境将取决于你的代码库的健康状况以及你是否遵循了 [React 的规则](/reference/rules)
138+
=======
139+
The compiler is now in RC and has been tested extensively in production. 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).
140+
>>>>>>> 740016e4dea7e518bd045309bc3e828cc2a787a4
121141
122142
**你现在不必急着使用编译器。在采用它之前等到它达到稳定版本是可以的。** 然而,我们确实赞赏在你的应用程序中进行小型实验,以便你可以向我们 [提供反馈](#reporting-issues),帮助使编译器更好。
123143

124144
## 开始 {/*getting-started*/}
125145

126146
除了这些文档之外,我们还建议查看 [React Compiler 工作组](https://github.com/reactwg/react-compiler),以获取有关编译器的更多信息和讨论。
127147

148+
<<<<<<< HEAD
128149
### 安装 eslint-plugin-react-compiler {/*installing-eslint-plugin-react-compiler*/}
129150

130151
React Compiler 还为 ESLint 插件提供支持。ESLint 插件可以**独立**于编译器使用,这意味着即使你不使用编译器,也可以使用 ESLint 插件。
152+
=======
153+
### Installing eslint-plugin-react-hooks {/*installing-eslint-plugin-react-compiler*/}
154+
155+
React Compiler also powers an ESLint plugin. You can try it out by installing eslint-plugin-react-hooks@^6.0.0-rc.1.
156+
>>>>>>> 740016e4dea7e518bd045309bc3e828cc2a787a4
131157
132158
<TerminalBlock>
133-
npm install -D eslint-plugin-react-compiler@beta
159+
{`npm install -D eslint-plugin-react-hooks@^6.0.0-rc.1`}
134160
</TerminalBlock>
135161

162+
<<<<<<< HEAD
136163
然后,将其添加到你的 ESLint 配置中:
137164

138165
```js
@@ -162,6 +189,9 @@ module.exports = {
162189
},
163190
}
164191
```
192+
=======
193+
See our [editor setup](/learn/editor-setup#linting) guide for more details.
194+
>>>>>>> 740016e4dea7e518bd045309bc3e828cc2a787a4
165195
166196
ESLint 插件将在编辑器中显示任何违反 React 规则的行为。当它这样做时,这意味着编译器跳过了优化该组件或钩子。这是完全可以的,编译器可以恢复并继续优化代码库中的其他组件。
167197

@@ -195,7 +225,7 @@ const ReactCompilerConfig = {
195225
React Compiler 与 React 19 RC 配合使用效果最佳。如果你无法升级,可以安装额外的 `react-compiler-runtime` 包来编译代码并在 19 之前的版本上运行。 但请注意,支持的最低版本是 17。
196226

197227
<TerminalBlock>
198-
npm install react-compiler-runtime@beta
228+
{`npm install react-compiler-runtime@rc`}
199229
</TerminalBlock>
200230

201231
你还应该在编译器配置中添加正确的 `target`,值为你所使用的 React 大版本。
@@ -230,7 +260,7 @@ React Compiler 还可用于编译库。由于 React Compiler 需要在代码转
230260
### Babel {/*usage-with-babel*/}
231261

232262
<TerminalBlock>
233-
npm install babel-plugin-react-compiler@beta
263+
{`npm install babel-plugin-react-compiler@rc`}
234264
</TerminalBlock>
235265

236266
编译器包含一个 Babel 插件,你可以在构建流水线中使用它来运行编译器。
@@ -285,7 +315,7 @@ export default defineConfig(() => {
285315
安装 `vite-plugin-babel`, 并将编译器的 Babel 插件添加到其中:
286316

287317
<TerminalBlock>
288-
npm install vite-plugin-babel
318+
{`npm install vite-plugin-babel`}
289319
</TerminalBlock>
290320

291321
```js {2,14}

src/content/reference/react-dom/client/hydrateRoot.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,12 +380,13 @@ It is uncommon to call [`root.render`](#root-render) on a hydrated root. Usually
380380
381381
By default, React will log all errors to the console. To implement your own error reporting, you can provide the optional error handler root options `onUncaughtError`, `onCaughtError` and `onRecoverableError`:
382382
383-
```js [[1, 6, "onCaughtError"], [2, 6, "error", 1], [3, 6, "errorInfo"], [4, 10, "componentStack", 15]]
383+
```js [[1, 7, "onCaughtError"], [2, 7, "error", 1], [3, 7, "errorInfo"], [4, 11, "componentStack", 15]]
384384
import { hydrateRoot } from "react-dom/client";
385+
import App from "./App.js";
385386
import { reportCaughtError } from "./reportError";
386387

387388
const container = document.getElementById("root");
388-
const root = hydrateRoot(container, {
389+
const root = hydrateRoot(container, <App />, {
389390
onCaughtError: (error, errorInfo) => {
390391
if (error.message !== "Known error") {
391392
reportCaughtError({

0 commit comments

Comments
 (0)