How to React Compiler

This ad is not shown to multipass and full ticket holders
React Summit US
React Summit US 2025
November 18 - 21, 2025
New York, US & Online
The biggest React conference in the US
Learn More
In partnership with Focus Reactive
Upcoming event
React Summit US 2025
React Summit US 2025
November 18 - 21, 2025. New York, US & Online
Learn more
Bookmark
Rate this content

It's been several months since the release of React Compiler Beta, but for some reason there are hardly any talks describing this tool in all depth.

I mean, what are those dozens of tabs on the React Compiler Playground website? How does those 30+ environment flags work? And most importantly, can it affect my React website in production and can I benefit from utilizing all of these settings and tools?

Let's dive deep (and I mean really deep) into the React Compiler source code and see how flexible this tool is and what are the challenges of working with it?

This talk has been presented at React Summit 2025, check out the latest edition of this React Conference.

FAQ

The speaker is Anton Nevsha, a front-end engineer with 11 years of commercial experience.

No, the React compiler is not the same as React 19. Installing React 19 alone will not provide the benefits of the React compiler.

To use the React compiler, you need to install the Babel plugin 'React Compiler' from NPM and specify it in the V configuration file.

During its beta phase, the React compiler may throw errors like 'to-do' or 'invariant,' indicating unfinished features or development.

The React compiler may execute hooks more often than expected, affecting memorization. Workarounds include renaming hooks or restructuring code to avoid unnecessary executions.

The React compiler helps improve code structure, making components cleaner and simpler, though short-term performance gains may not be significant if hooks are already well-optimized.

The React compiler is a tool that offers features like automatic memorization and can optimize React components by detecting dependencies and recomputing outputs only when necessary.

The enable function outlining feature is responsible for extracting the JSX part from array map callbacks, but it has limitations, such as not tolerating variables declared outside the map callback scope.

To see hidden error messages, enable the 'validate preserve existing memorization guarantees' flag in the plugin configuration.

Anton Nepsha
Anton Nepsha
20 min
17 Jun, 2025

Comments

Sign in or register to post your comment.
Video Summary and Transcription
Introduction to React compiler, differences from React 19, installation of Babel plug-in React compiler, specifying target React versions, and how React compiler detects and processes component dependencies. Configuring React compiler settings, exploring default options and configurations, utilizing React compiler playground website for configurations, dealing with JSX markup re-computation. React compiler feature for extracting JSX from array map callbacks, limitations of enable function outlining, enabling JSX outlining for separate functions. Function memoization in React compiler, React compiler beta stage, potential errors with React compiler. React compiler error: memorization preservation, hidden messages, validation settings. React compiler: validation tools, hooks treatment, memorization challenges. Changing hooks to functions for React compiler optimization. React Compiler usage considerations and potential optimizations.
Available in Español: How to React Compiler

1. Introduction to React Compiler

Short description:

Introduction to React compiler, differences from React 19, installation of Babel plug-in React compiler, specifying target React versions, and how React compiler detects and processes component dependencies.

Hello, everyone, and welcome to my talk about the React compiler. My name is Anton Nevsha, and let me introduce myself real quick first before we dive into the React compiler world. I have 11 years of commercial experience as a front-end engineer, and events and conferences like React Summit is really what inspires me and makes my life better. So, yeah, really glad to be with you here today.

For my career, I develop online banking apps, and some of those are actually in production, working on the React compiler. So, I just really wanted to share with you my experience with the adoption of this technology, of this tool. And let me start off by stating that the React compiler is not the same as React 19, right? So, for some of us who are still getting familiar themselves with the technology, it's worth noting that just installing React 19 won't give you the benefit of those automatic memorizations and other features that React compiler has to offer.

So we would need to install yet another package called Babel plug-in React compiler, which is a separate package from the NPM. And this is pretty straightforward to configure it and to install it, because all we have to do is to specify the name of the plugin in our V configuration file, and we're good to go. Another thing is that we can also specify the target version of React if we are working with the older versions of React, let's say 17 or 18. And configure it this way would give us this result. This is the output file, and the input component, and the output component that is processed with the React compiler. What it basically does is it detects the props or variables that our component is dependent on, and based on their behavior, if they're changed or not, it would recompute the output of the component or just return the pre-computed output of the component.

2. Configuring React Compiler

Short description:

Configuring React compiler settings, exploring default options and configurations, utilizing React compiler playground website for configurations, dealing with JSX markup re-computation.

And that is basically it. But the interesting thing about this is that, if we configure our React compiler like this, placing this little configuration object in the plugin configuration file, we would actually end up with having this much settings, and this much options and configurations. Those are the default options that React compiler has to offer, and we would actually be careful with those, because some of them are straightforward, but others, like this environment key, it basically contains an object with 30 or 30-ish other configurations and options.

And if you want to see what it's doing and see what they are, the best place to refer to is actually React compiler playground website. And here on the right side, there is this environment config section, which is expandable, and no one actually talks about it for some reason. Never. But this is the best place to figure out what configuration is best for your project, basically. And here on the left side, there is the sample component that I'm using.

This is the type of components that we've all seen. There is this list function that accepts a people array, and the problem is that we have to iterate over each element within this array to create some sort of JSX markup. And it's no big deal, right? But the fact is that whenever any of the items within the array change, or if we, let's say, add some more items to the array, we would still have to recompute all the items within this array once again. And normally, before React compiler, we would end up extracting this JSX part into a separate component and also wrapping it in react.memo, just to make sure we wouldn't recompute those items again.

3. Enhancing JSX Extraction in React Compiler

Short description:

React compiler feature for extracting JSX from array map callbacks, limitations of enable function outlining, enabling JSX outlining for separate functions.

And the brilliant part about React compiler is that it actually has the same feature extracting the JSX part from the array map callbacks. It can do this automatically for us, and the problem is that the feature that is responsible for doing it is enabled by default. But in this example, we still don't get the automatic memorization. We still don't see how this JSX is being extracted because this JSX part is still a part of the larger function. It's not a separate function. Well, why is that? Because the enable function outlining over here is set to true, and this is the exact option that is responsible for extracting it.

Well, the thing is that this enable function outlining feature has its own limits. The particular issue here is that, in our components, we have this style variable defined, and the problem is that it is declared outside of the array map callback scope. You see it's declared outside, and this is something that enable function outlining cannot tolerate and cannot work with. But luckily, we still have some workarounds with the environment, and we can also enable another feature called enable JSX outlining, which is currently set to false by default, but we can easily enable it. It's a little bit tricky in the Playground website because this right part is not editable. You cannot write anything here. You cannot type anything or change anything here.

So, how do we enable all the flags that we want to? Well, this is actually pretty simple. We would have just to add a comment somewhere above our function and add an annotation corresponding to the flag that we want to enable. This annotation enable JSX outlining, which we placed here, would enable the JSX outlining flag over here, which, in turn, would change the output of the React compiler. And now you can see that we have a different output, basically. We have this const t0 equals underscore temp, and this underscore temp function is basically a separate function, absolutely independent from what we had before. This function is declared here in the below the previous component. And we see that this function actually looks like a React component that is being memoized in the same way that React.Memo does.

4. Common Issues and Errors with React Compiler

Short description:

Function memoization in React compiler, React compiler beta stage, potential errors with React compiler.

And we see that this function actually looks like a React component that is being memoized in the same way that React.Memo does. So, this is great news, and this is something we can work with. Great.

One major thing about React compiler is that while I worked with React compiler, it was still in beta. And when the project is in beta, it's not a surprise that something can change. Something can be developed further. Something can be not quite as good yet. In order for us to not break anything and to make sure the integrity of our app did not suffer, we should at least know what can be broken.

These are the things that can be broken with or without React compiler. These are the error messages that you get when working with the React compiler, and those three are pretty straightforward. When you have invalid JS or invalid React, it's no surprise that React compiler won't deal with it. It's not React compiler-specific. This is something no Babel plugin would tolerate and would break. If you have a valid configuration, it can also result in an invalid output. But there are some specifics for React compiler, and some of them are quite funny.

One of those is to-do or invariant. Those are basically some internal React compiler errors that might tell you that something is not finished yet with the development of the React compiler itself. As an example, I can give you this component. Whenever you have the variable called FBT declared somewhere in your components, you see that you may not even want to use that. But just the fact that you have this variable and it has the name FBT makes React compiler throw an error at you, saying that the support of the local variables with the name FBT is not supported yet.

5. Preserving Memorization in React Compiler

Short description:

React compiler error: memorization preservation, hidden messages, validation settings.

But this is just a fun thing to keep in mind, and I'm sure it's going to be fixed soon. But there is one more important error that you might come across, which is that it cannot preserve memorization. Now, this error occurs when React compiler cannot guarantee us that the memorization level that we had is the same after the React compiler does its job. So, it's not sure if the level of memorization stays the same. This is a big deal. This is great news that we have these errors stating that some of the components aren't that well memorized as they used to be.

But the fact is that this error message is hidden by default. If you want to see those error messages, you may want to specify the panic threshold setting in your plugin configuration, basically so that you'll be able to see which component is not supported by React compiler and which is doing okay. So, by default, what React compiler does is just skip the component that it cannot memorize properly. If you want to see some more info about that, you may want to enable this feature. And one more useful thing is that there's this environment flag called validate preserve existing memorization guarantees.

Now, what it does is, actually, it is responsible for throwing that cannot preserve memorization error. So, if you enable this validate preserve existing memorization guarantees flag, you will see those errors more often, and you would more often see if some of the components aren't being memorized good enough. This flag is recommended by the React compiler team to be enabled when you're migrating your codebase to the React compiler, but it's disabled by default. Make sure to enable it to see what's going on with your codebase. What this option does is, basically, it gives you errors when somewhere in your codebase there are hook dependencies that are used wrong, or some hook mutations going on, or some other rules of React being broken.

6. React Compiler Validation and Hooks Treatment

Short description:

React compiler: validation tools, hooks treatment, memorization challenges.

There are more validation tools and more validation options you can specify if you want, but those are also straightforward and speak for themselves. Like validate no set state in render, this is clear what it means. So, you can specify those if you really need them. And there are some other lessons that I've learned with React compiler when working with it, and one of my favorite things is the way React compiler treats hooks.

Let's imagine we have this example component that uses this useAccessibility hook. It doesn't actually matter what exactly it does, but all that matters is that it's a useMemo. If we know useMemo, it's pretty straightforward. It just remembers dependency variables and fires the function if the dependency change. So, I have this console log over here, but we are pretty certain that this console log wouldn't be executed if product or flag dependencies aren't changed.

But, let's see what's going on with this component and with this hook after we compile those with React compiler. Now, as for the component itself, this is pretty simple, actually. We still have this useAccessibility hook call, and if it's a hook call, we cannot place it within the if statement or within a conditional. So, it's basically where it belongs. It's the top level of the function, and it's been executed each time the component is being rendered. But, as for the hook itself, well, now we see that this console log is being executed far more often because it's been executed even before we check the flag or product dependency. So, this is some sort of change in behavior and changing the way we memorize things, and there are several ways to deal with that.

7. Optimizing React Compiler Hooks

Short description:

Changing hooks to functions for React compiler optimization.

The first thing that can help us is just changing the way we work with hooks and just renaming them and getting rid of the hook itself. Let's say we have the useAccessibility hook, and we should convert it into a getAccessibility function that won't work as a hook, and won't comply with the naming conventions of the hook, and won't be compiled by React compiler. Imagine what we had before. We had this useAccessibility hook executed every time. But, if we had the getAccessibility function, it would be pretty normal to just place it within the if statement, thus retaining the same level of memorization that we had before.

This is great news, and another example of how we can do this is we can just use those declarations like useNoMemo or useNoForget. Those declarations would tell React compiler to skip the component or the hook, and it will remain the same as it used to be. This is also the way to retain the same level of memorization. Another workaround is just not to keep this logic in the view layer. You can just place it somewhere in your state manager, or somewhere above the React layer, somewhere like this.

Let's also talk about hook return values. They should be mutable, since it's a React rule, and, while working with them, imagine this example where we have this status key variable, which is a result of useMemo call. Whenever we pass it into some function, even though this function might not even mutate this exactly, like this internationalization translate function, which does not mutate the key, it just accepts it. But still, React compiler wouldn't be happy with that. It would throw us an error, because we basically violate the rule of React to mutate this hook return value. What we can do with that is just reorder some project structure a little bit, or we can disable the environment flag that I told you before, validate preserve existing memorization guarantees.

8. React Compiler Component PR Considerations

Short description:

React Compiler usage considerations and potential optimizations.

If we set it to false, it won't react to those situations, even though it's a violation of React rule, and it should react to that. Or, you can just get rid of useMemo, because this is a classic example of us just removing the useMemo completely, and having the same output as before, because this is what we would get. This is just the same as with using useMemo.

So, we have this getStatusKey function that's being executed only if the entity variable is changed. This is exactly what we need. There is more to this component example. I just wanted to illustrate you a little bit a little tricky situation. So, imagine you have this component. This is the same component that we used before, the one with the status key. Let us imagine that one of your co-workers opens a PR, trying to add some more data in this component.

Let's say they just add a name property, and they change the JSX output a little bit. This is no big deal, and we would accept this PR, most certainly, even though we just won't talk about why the name property and entity are separate properties, but let's leave it as it is, and accept this PR. But, if we would use React Compiler, we would want to give this PR a second thought, basically, because this is what our component looked like before the PR.

Check out more articles and videos

We constantly think of articles and videos that might spark Git people interest / skill us up or help building a stellar career

A Guide to React Rendering Behavior
React Advanced 2022React Advanced 2022
25 min
A Guide to React Rendering Behavior
Top Content
This transcription provides a brief guide to React rendering behavior. It explains the process of rendering, comparing new and old elements, and the importance of pure rendering without side effects. It also covers topics such as batching and double rendering, optimizing rendering and using context and Redux in React. Overall, it offers valuable insights for developers looking to understand and optimize React rendering.
Building Better Websites with Remix
React Summit Remote Edition 2021React Summit Remote Edition 2021
33 min
Building Better Websites with Remix
Top Content
Remix is a web framework built on React Router that focuses on web fundamentals, accessibility, performance, and flexibility. It delivers real HTML and SEO benefits, and allows for automatic updating of meta tags and styles. It provides features like login functionality, session management, and error handling. Remix is a server-rendered framework that can enhance sites with JavaScript but doesn't require it for basic functionality. It aims to create quality HTML-driven documents and is flexible for use with different web technologies and stacks.
React Compiler - Understanding Idiomatic React (React Forget)
React Advanced 2023React Advanced 2023
33 min
React Compiler - Understanding Idiomatic React (React Forget)
Top Content
Watch video: React Compiler - Understanding Idiomatic React (React Forget)
Joe Savona
Mofei Zhang
2 authors
The Talk discusses React Forget, a compiler built at Meta that aims to optimize client-side React development. It explores the use of memoization to improve performance and the vision of Forget to automatically determine dependencies at build time. Forget is named with an F-word pun and has the potential to optimize server builds and enable dead code elimination. The team plans to make Forget open-source and is focused on ensuring its quality before release.
Using useEffect Effectively
React Advanced 2022React Advanced 2022
30 min
Using useEffect Effectively
Top Content
Today's Talk explores the use of the useEffect hook in React development, covering topics such as fetching data, handling race conditions and cleanup, and optimizing performance. It also discusses the correct use of useEffect in React 18, the distinction between Activity Effects and Action Effects, and the potential misuse of useEffect. The Talk highlights the benefits of using useQuery or SWR for data fetching, the problems with using useEffect for initializing global singletons, and the use of state machines for handling effects. The speaker also recommends exploring the beta React docs and using tools like the stately.ai editor for visualizing state machines.
Routing in React 18 and Beyond
React Summit 2022React Summit 2022
20 min
Routing in React 18 and Beyond
Top Content
Routing in React 18 brings a native app-like user experience and allows applications to transition between different environments. React Router and Next.js have different approaches to routing, with React Router using component-based routing and Next.js using file system-based routing. React server components provide the primitives to address the disadvantages of multipage applications while maintaining the same user experience. Improving navigation and routing in React involves including loading UI, pre-rendering parts of the screen, and using server components for more performant experiences. Next.js and Remix are moving towards a converging solution by combining component-based routing with file system routing.
React Concurrency, Explained
React Summit 2023React Summit 2023
23 min
React Concurrency, Explained
Top Content
Watch video: React Concurrency, Explained
React 18's concurrent rendering, specifically the useTransition hook, optimizes app performance by allowing non-urgent updates to be processed without freezing the UI. However, there are drawbacks such as longer processing time for non-urgent updates and increased CPU usage. The useTransition hook works similarly to throttling or bouncing, making it useful for addressing performance issues caused by multiple small components. Libraries like React Query may require the use of alternative APIs to handle urgent and non-urgent updates effectively.

Workshops on related topic

React Performance Debugging Masterclass
React Summit 2023React Summit 2023
170 min
React Performance Debugging Masterclass
Top Content
Featured Workshop
Ivan Akulov
Ivan Akulov
Ivan’s first attempts at performance debugging were chaotic. He would see a slow interaction, try a random optimization, see that it didn't help, and keep trying other optimizations until he found the right one (or gave up).
Back then, Ivan didn’t know how to use performance devtools well. He would do a recording in Chrome DevTools or React Profiler, poke around it, try clicking random things, and then close it in frustration a few minutes later. Now, Ivan knows exactly where and what to look for. And in this workshop, Ivan will teach you that too.
Here’s how this is going to work. We’ll take a slow app → debug it (using tools like Chrome DevTools, React Profiler, and why-did-you-render) → pinpoint the bottleneck → and then repeat, several times more. We won’t talk about the solutions (in 90% of the cases, it’s just the ol’ regular useMemo() or memo()). But we’ll talk about everything that comes before – and learn how to analyze any React performance problem, step by step.
(Note: This workshop is best suited for engineers who are already familiar with how useMemo() and memo() work – but want to get better at using the performance tools around React. Also, we’ll be covering interaction performance, not load speed, so you won’t hear a word about Lighthouse 🤐)
Next.js for React.js Developers
React Day Berlin 2023React Day Berlin 2023
157 min
Next.js for React.js Developers
Top Content
Featured WorkshopFree
Adrian Hajdin
Adrian Hajdin
In this advanced Next.js workshop, we will delve into key concepts and techniques that empower React.js developers to harness the full potential of Next.js. We will explore advanced topics and hands-on practices, equipping you with the skills needed to build high-performance web applications and make informed architectural decisions.
By the end of this workshop, you will be able to:1. Understand the benefits of React Server Components and their role in building interactive, server-rendered React applications.2. Differentiate between Edge and Node.js runtime in Next.js and know when to use each based on your project's requirements.3. Explore advanced Server-Side Rendering (SSR) techniques, including streaming, parallel vs. sequential fetching, and data synchronization.4. Implement caching strategies for enhanced performance and reduced server load in Next.js applications.5. Utilize React Actions to handle complex server mutation.6. Optimize your Next.js applications for SEO, social sharing, and overall performance to improve discoverability and user engagement.
Concurrent Rendering Adventures in React 18
React Advanced 2021React Advanced 2021
132 min
Concurrent Rendering Adventures in React 18
Top Content
Featured Workshop
Maurice de Beijer
Maurice de Beijer
With the release of React 18 we finally get the long awaited concurrent rendering. But how is that going to affect your application? What are the benefits of concurrent rendering in React? What do you need to do to switch to concurrent rendering when you upgrade to React 18? And what if you don’t want or can’t use concurrent rendering yet?

There are some behavior changes you need to be aware of! In this workshop we will cover all of those subjects and more.

Join me with your laptop in this interactive workshop. You will see how easy it is to switch to concurrent rendering in your React application. You will learn all about concurrent rendering, SuspenseList, the startTransition API and more.
React Hooks Tips Only the Pros Know
React Summit Remote Edition 2021React Summit Remote Edition 2021
177 min
React Hooks Tips Only the Pros Know
Top Content
Featured Workshop
Maurice de Beijer
Maurice de Beijer
The addition of the hooks API to React was quite a major change. Before hooks most components had to be class based. Now, with hooks, these are often much simpler functional components. Hooks can be really simple to use. Almost deceptively simple. Because there are still plenty of ways you can mess up with hooks. And it often turns out there are many ways where you can improve your components a better understanding of how each React hook can be used.You will learn all about the pros and cons of the various hooks. You will learn when to use useState() versus useReducer(). We will look at using useContext() efficiently. You will see when to use useLayoutEffect() and when useEffect() is better.
Introducing FlashList: Let's build a performant React Native list all together
React Advanced 2022React Advanced 2022
81 min
Introducing FlashList: Let's build a performant React Native list all together
Top Content
Featured Workshop
David Cortés Fulla
Marek Fořt
Talha Naqvi
3 authors
In this workshop you’ll learn why we created FlashList at Shopify and how you can use it in your code today. We will show you how to take a list that is not performant in FlatList and make it performant using FlashList with minimum effort. We will use tools like Flipper, our own benchmarking code, and teach you how the FlashList API can cover more complex use cases and still keep a top-notch performance.You will know:- Quick presentation about what FlashList, why we built, etc.- Migrating from FlatList to FlashList- Teaching how to write a performant list- Utilizing the tools provided by FlashList library (mainly the useBenchmark hook)- Using the Flipper plugins (flame graph, our lists profiler, UI & JS FPS profiler, etc.)- Optimizing performance of FlashList by using more advanced props like `getType`- 5-6 sample tasks where we’ll uncover and fix issues together- Q&A with Shopify team
React, TypeScript, and TDD
React Advanced 2021React Advanced 2021
174 min
React, TypeScript, and TDD
Top Content
Featured Workshop
Paul Everitt
Paul Everitt
ReactJS is wildly popular and thus wildly supported. TypeScript is increasingly popular, and thus increasingly supported.

The two together? Not as much. Given that they both change quickly, it's hard to find accurate learning materials.

React+TypeScript, with JetBrains IDEs? That three-part combination is the topic of this series. We'll show a little about a lot. Meaning, the key steps to getting productive, in the IDE, for React projects using TypeScript. Along the way we'll show test-driven development and emphasize tips-and-tricks in the IDE.