Skip to content

Commit ee09492

Browse files
authored
[compiler] Move React 17/18 section to its own subheading (#7230)
Currently it's a little hidden, let's move it to its own subheading for more prominence
1 parent 2bd6189 commit ee09492

File tree

1 file changed

+25
-29
lines changed

1 file changed

+25
-29
lines changed

src/content/learn/react-compiler.md

+25-29
Original file line numberDiff line numberDiff line change
@@ -192,61 +192,63 @@ export default function App() {
192192

193193
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.
194194

195-
#### New projects {/*new-projects*/}
196-
197-
If you're starting a new project, you can enable the compiler on your entire codebase, which is the default behavior.
195+
### Using React Compiler with React 17 or 18 {/*using-react-compiler-with-react-17-or-18*/}
198196

199-
## Usage {/*installation*/}
200-
201-
### Babel {/*usage-with-babel*/}
197+
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.
202198

203199
<TerminalBlock>
204-
npm install babel-plugin-react-compiler@experimental
200+
npm install react-compiler-runtime@experimental
205201
</TerminalBlock>
206202

207-
The compiler includes a Babel plugin which you can use in your build pipeline to run the compiler.
208-
209-
After installing, add it to your Babel config. Please note that it's critical that the compiler run **first** in the pipeline:
203+
You should also add the correct `target` to your compiler config, where `target` is the major version of React you are targeting:
210204

211-
```js {7}
205+
```js {3}
212206
// babel.config.js
213-
const ReactCompilerConfig = { /* ... */ };
207+
const ReactCompilerConfig = {
208+
target: '18' // '17' | '18' | '19'
209+
};
214210

215211
module.exports = function () {
216212
return {
217213
plugins: [
218-
['babel-plugin-react-compiler', ReactCompilerConfig], // must run first!
219-
// ...
214+
['babel-plugin-react-compiler', ReactCompilerConfig],
220215
],
221216
};
222217
};
223218
```
224219

225-
`babel-plugin-react-compiler` should run first before other Babel plugins as the compiler requires the input source information for sound analysis.
220+
#### New projects {/*new-projects*/}
226221

227-
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.
222+
If you're starting a new project, you can enable the compiler on your entire codebase, which is the default behavior.
223+
224+
## Usage {/*installation*/}
225+
226+
### Babel {/*usage-with-babel*/}
228227

229228
<TerminalBlock>
230-
npm install react-compiler-runtime@experimental
229+
npm install babel-plugin-react-compiler@experimental
231230
</TerminalBlock>
232231

233-
You should also add the correct `target` to your compiler config, where `target` is the major version of React you are targeting:
232+
The compiler includes a Babel plugin which you can use in your build pipeline to run the compiler.
234233

235-
```js {3}
234+
After installing, add it to your Babel config. Please note that it's critical that the compiler run **first** in the pipeline:
235+
236+
```js {7}
236237
// babel.config.js
237-
const ReactCompilerConfig = {
238-
target: '18' // '17' | '18' | '19'
239-
};
238+
const ReactCompilerConfig = { /* ... */ };
240239

241240
module.exports = function () {
242241
return {
243242
plugins: [
244-
['babel-plugin-react-compiler', ReactCompilerConfig],
243+
['babel-plugin-react-compiler', ReactCompilerConfig], // must run first!
244+
// ...
245245
],
246246
};
247247
};
248248
```
249249

250+
`babel-plugin-react-compiler` should run first before other Babel plugins as the compiler requires the input source information for sound analysis.
251+
250252
### Vite {/*usage-with-vite*/}
251253

252254
If you use Vite, you can add the plugin to vite-plugin-react:
@@ -392,12 +394,6 @@ To report issues, please first create a minimal repro on the [React Compiler Pla
392394

393395
You can also provide feedback in the React Compiler Working Group by applying to be a member. Please see [the README for more details on joining](https://github.com/reactwg/react-compiler).
394396

395-
### `(0 , _c) is not a function` error {/*0--_c-is-not-a-function-error*/}
396-
397-
This occurs if you are not using React 19 RC and up. To fix this, [upgrade your app to React 19 RC](https://react.dev/blog/2024/04/25/react-19-upgrade-guide) first.
398-
399-
If you are unable to upgrade to React 19, you may try a userspace implementation of the cache function as described in the [Working Group](https://github.com/reactwg/react-compiler/discussions/6). However, please note that this is not recommended and you should upgrade to React 19 when possible.
400-
401397
### How do I know my components have been optimized? {/*how-do-i-know-my-components-have-been-optimized*/}
402398

403399
[React Devtools](/learn/react-developer-tools) (v5.0+) has built-in support for React Compiler and will display a "Memo ✨" badge next to components that have been optimized by the compiler.

0 commit comments

Comments
 (0)