r/reactjs • • 15h ago

Discussion React Compiler Working Structure

React Compiler was introduced in React 19 so I want to know that how it works internally. Seeking deep research knowledge on React Compiler in simple English.

0 Upvotes

10 comments sorted by

1

u/Top_Bumblebee_7762 12h ago

There is a React compiler marker extension that can show you the optimized output so you can analyse it. 

0

u/HamzaSiddiqueDev 12h ago

Can you please share the extension?

2

u/Top_Bumblebee_7762 12h ago

It's called React compiler marker

2

u/Maybe_I-am_Ahsan 9h ago

the compiler marker extension tip is gold, seeing the optimized output beats reading docs about it

2

u/anthony-ball 5h ago

Worth knowing first: it isn't really part of React 19 itself, it's a separate build-time Babel plugin (babel-plugin-react-compiler) and it also works on 17/18 with the runtime package. At build time it reads each component and hook, works out which values depend on which props and state, and caches those pieces in a per-component memo cache, so it's basically auto useMemo/useCallback/React.memo but more granular than you'd ever write by hand. If a component breaks the Rules of React (mutating props, reading refs during render, etc.) it just skips that component instead of guessing. The quickest way to actually get it is playground.react.dev: paste a small component and read the compiled output side by side.

2

u/allaboutzaid 3h ago

Thanks for asking this in simple terms — I am learning React too, and the part that finally clicked for me from the replies here is that the Compiler is a separate build-time Babel plugin, not something running in the browser. It reads each component before the app ships and memoizes the values and hooks for you, so you write normal code and it skips the re-renders you would otherwise hand-optimize. That also explains why it works on React 17 and 18, which I did not expect.

1

u/atta542 14h ago

short version: it's a babel plugin that runs at build time, it's not something running inside react itself. it turns each component into its own intermediate representation, works out which values depend on which props and state, and then rewrites the component so those values get cached. if you paste a component into the react compiler playground you'll see a _c(n) call at the top of the output, that's a cache array, and the compiled code checks whether the inputs changed before recomputing things or recreating jsx. so it's basically writing the useMemo/useCallback/memo you would have written by hand. the playground is honestly the easiest way to get it, look at input and output side by side for a few components