React Compiler — Goals, Design Principles, and Architecture

This document describes the goals, design principles, and high-level architecture of React Compiler. See the code for specifics of the data structures and compiler passes.

Goals

The idea of React Compiler is to allow developers to use React's familiar declarative, component-based programming model, while ensuring that apps are fast by default. Concretely we seek to achieve the following goals:

Non-Goals

The following are explicitly not goals for React Compiler:

Design Principles

Many aspects of the design follow naturally from the above goals:

Architecture

React Compiler has two primary public interfaces: a Babel plugin for transforming code, and an ESLint plugin for reporting violations of the Rules of React. Internally, both use the same core compiler logic.

The core of the compiler is largely decoupled from Babel, using its own intermediate representations. The high-level flow is as follows:

The ESLint plugin works similarly. For now, it effectively invokes the Babel plugin on the code and reports back a subset of the errors. The compiler can report a variety of errors, including that the code is simply invalid JavaScript, but the ESLint plugin filters to only show the React-specific errors.