AI summary by TwinMind

React Compiler: It's Stranger Than You Think

Theo - t3․gg

27m 36s

React Compiler Overview and Philosophy

  • React compiler transforms simple input to simple output - easy to understand generated code
  • Performance wins already proven when memoizing everything properly (JS benchmark examples)
  • Issue: manual memoization gets worse as code complexity/requirements change over time
  • Compiler provides "close enough" performance automatically vs forcing developers to write perfect code
  • Makes React feel more like Go - don't manage memory/memoization yourself, let tooling handle it

Compiler Behavior with Existing Memoization

  • Rewrites components with useMemo only if compiler's memoization covers same values as manual version
  • If manual memoization differs, compiler skips that component entirely
  • Doesn't override explicit developer decisions - only adds optimization where none existed
  • Prevents regression in logic/effect dependencies due to different memoization approaches

Rules of React Enforcement

  • Compiler enforces Rules of React statically for first time
  • Acts as linter for React language rules (don't mutate props, etc.)
  • New ESLint rules cover components, memoization expectations, much more than just hooks
  • Code must follow rules to be optimizable - creates incentive/carrot for idiomatic React code
  • Better than linter because fixing violations makes code faster (compiler stops skipping)

Prop Mutation Problem Example

  • JavaScript allows mutating props passed by reference
  • Example: props.names.reverse() modifies original array, causes rendering bugs
  • Strict mode helps by throwing errors on prop mutation
  • Solution requires spreading arrays: [...props.names].reverse()
  • New lint rules will catch these violations automatically

Fine-Grained Reactivity Approach

  • All information for fine-grained reactivity already exists in React code
  • Can visually see what should be memoized (filtered songs only change when songs change)
  • Compiler transforms code into what it "obviously should be doing"
  • No mental model change required unlike signals-based frameworks
  • Average React dev doesn't need to understand implementation details

Comparison with Other Frameworks

Solid JS Signals Model

  • Values wrapped in functions that bind signals when called
  • first() returns value and creates reactive dependency
  • Not bare JavaScript values - requires planning data flow from creation to consumption
  • More explicit but requires wrapper components (Show, For) instead of native JS constructs
  • Runs components once then forces updates separately

React's Approach

  • Keeps plain JavaScript values and native constructs (if statements, map, etc.)
  • Data flow graph already visible in code structure
  • Compiler analyzes ahead of time vs runtime reactive construction
  • Similar to Svelte 3 approach - acknowledge Rich Harris was right

Technical Implementation Details

  • React compiler: if (prevCount !== count) jsx = newValue else jsx = prevValue
  • Svelte approach: if (prevCount !== count) updateCounter(count)
  • React compiler bails out on shallow comparison (e.g., n = list1.length + list2.length stays same when item moves between lists)
  • Compares result values vs triggering reactive chains

Team Building and History

Key Contributors

  • Joe Savona: Originally frustrated with Relay integration, ended up building compiler
  • Moved from external store hooks frustration to understanding React's approach
  • Mofei Zhan: Compiler expertise wizard
  • Lauren: Strong technical understanding
  • Multiple attempts before success (Zan Hang's original work, Sebastian's vision)

Historical Context

  • Compiler concept existed before hooks - hooks came from compiler research
  • Prepack attempts led to understanding optimizable APIs
  • Resulted in both hooks and RSCs development
  • Required rare combination of UI and compiler expertise
  • Team assembly as impressive as technical implementation

Development Philosophy

  • "Ruthless pragmatism" - works on pure JavaScript without new syntax or static types
  • Chose not to require Flow-like primitives despite optimization benefits
  • First hooks implementation included compiler runtime methods (never shipped)
  • Multiple failed attempts (prepack) before current success
  • Transparency in sharing both successes and failures

Communication and Transparency

  • React team shares work-in-progress code publicly (including Rust compiler attempts)
  • 358,000 line PR with experimental Rust code visible in repo
  • Unusual level of transparency compared to other projects
  • Public notes, broken early implementations available for inspection
  • Contrast with other frameworks that hide early work until ready

TwinMind

Get summaries like this for your own meetings

TwinMind takes notes in the background during meetings, lectures, and calls, then writes the summary for you.

Free plan to get started

No bot joins your calls

Phone, desktop & Chrome apps

Your next meeting, summarized like this

TwinMind listens in the background and turns meetings, lectures, and calls into searchable notes you can chat with. Start free.

Available on phone, desktop & Chrome

Your next meeting, summarized like this

TwinMind listens in the background and turns meetings, lectures, and calls into searchable notes you can chat with. Start free.

Available on phone, desktop & Chrome

Your next meeting, summarized like this

TwinMind listens in the background and turns meetings, lectures, and calls into searchable notes you can chat with. Start free.

Available on phone, desktop & Chrome