Skip to content

Commit bb38630

Browse files
authored
Add react-compiler-runtime instructions to compiler docs (#7213)
For users of React < 19, there is a new react-compiler-runtime package that can be used to provide a "polyfill" for runtime APIs needed for compiled code. This PR adds docs for that.
1 parent 1697ae8 commit bb38630

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

src/content/learn/react-compiler.md

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ These docs are still a work in progress. More documentation is available in the
2020

2121
<Note>
2222
React Compiler is a new experimental compiler that we've open sourced to get early feedback from the community. It still has rough edges and is not yet fully ready for production.
23-
24-
React Compiler requires React 19 RC. 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.
2523
</Note>
2624

2725
React Compiler is a new experimental 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.
@@ -226,6 +224,29 @@ module.exports = function () {
226224

227225
`babel-plugin-react-compiler` should run first before other Babel plugins as the compiler requires the input source information for sound analysis.
228226

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.
228+
229+
<TerminalBlock>
230+
npm install react-compiler-runtime@experimental
231+
</TerminalBlock>
232+
233+
You should also add the correct `target` to your compiler config, where `target` is the major version of React you are targeting:
234+
235+
```js {3}
236+
// babel.config.js
237+
const ReactCompilerConfig = {
238+
target: '18' // '17' | '18' | '19'
239+
};
240+
241+
module.exports = function () {
242+
return {
243+
plugins: [
244+
['babel-plugin-react-compiler', ReactCompilerConfig],
245+
],
246+
};
247+
};
248+
```
249+
229250
### Vite {/*usage-with-vite*/}
230251

231252
If you use Vite, you can add the plugin to vite-plugin-react:

0 commit comments

Comments
 (0)