From React Code to Pixels: How Your React App Actually Becomes a Web Page
You write this:
function ProfileCard({ user }) {
const [liked, setLiked] = useState(false);return (
<div className="card">
<img src={user.avatar} alt={user.name} />
<h2>{user.name}</h2>
<p>{user.bio}</p>
<button onClick={() => setLiked(!liked)}>
{liked ? '❤️' : '🤍'}
</button>
</div>
);
}
A few milliseconds later, the user sees a rendered card on their screen. How? Let's trace the entire journey — from your keyboard to the GPU — step by step.
Phase 1: Build Time — JSX Becomes JavaScript
The browser doesn't understand JSX. It's not a valid web language. So before anything reaches a browser, Webpack (or whatever bundler you use) transforms your code.
Your JSX:
<div className="card">
<h2>{user.name}</h2>
</div>Gets compiled (by Babel) into:
React.createElement('div', { className: 'card' },
React.createElement('h2', null, user.name)
);Every JSX tag becomes a React.createElement(type, props, ...children) call. These calls create plain JavaScript objects called React elements. They look like this:
{
type: 'div',
props: {
className: 'card',
children: {
type: 'h2',
props: { children: 'Mani' },
// ...
}
}
}That's all JSX is — a convenient syntax for nested object creation. Nothing magical.
Phase 2: The Bundle Travels to the Browser
The bundler wraps all your components, along with React itself, into one or more JavaScript files. These files are linked in your HTML:<script src="/static/js/main.abc123.js"></script>
The user's browser downloads this bundle. On a slow network, that could be several seconds. Your React code is just text at this point.
Phase 3: JavaScript Parsing & Compilation
The browser's JavaScript engine (V8 in Chrome, SpiderMonkey in Firefox) receives your bundle as raw text. It needs to turn it into something executable. The steps:
1. Tokenization — breaks the text into tokens (function, const, return, etc.)
2. Parsing — builds an Abstract Syntax Tree (AST) representing your code's structure
3. Bytecode compilation — the AST is compiled into bytecode the machine can run
4. Optimization — hot code paths are further compiled into native machine code
This is where your app pays the startup cost. Every import, every component function, every hook — it all has to be parsed and compiled before it can run. A 500KB React bundle means 500KB of JavaScript that must go through this pipeline on the main thread, blocking everything else.
This is why React.lazy and code splitting exist — so you don't make the user parse code they don't need yet.
Phase 4: React Renders for the First Time
Now your code is ready to run. The browser executes your entry point:ReactDOM.createRoot(document.getElementById('root')).render(<App />);
This kicks off React's rendering pipeline.Step 4a: The Render Phase (Building the Virtual DOM)
React calls your App component function. That function returns React elements. Those elements reference child components, so React calls those too. This builds a tree of React elements — the Virtual DOM.
For our ProfileCard component, the Virtual DOM tree looks like:
App
└── ProfileCard (with props: { user: {...} })
└── div.card
├── img (src: user.avatar)
├── h2 (text: user.name)
├── p (text: user.bio)
└── button
└── (text: '🤍' or '❤️')
This tree is a pure JavaScript data structure — no DOM nodes have been created yet. It's just objects describing what the UI should look like.
React calls every component function in your tree, collects the returned elements, and compares the result with the previous Virtual DOM tree (if any). This comparison is called reconciliation.Step 4b: Reconciliation — The Diffing Algorithm
React walks the new and old Virtual DOM trees simultaneously, comparing each node:
- Same type, same position? React updates the existing DOM node with new props.
- Different type? React tears down the old DOM node and builds a new one.
- Key changed? React treats it as a new element (this is why key matters in lists).
For each difference React finds, it generates a mutation instruction: "update this attribute," "remove this node," "insert this text."Step 4c: The Commit Phase
Once React has the full list of mutations, it writes them to the real DOM. This happens synchronously in one shot:
// Pseudo-code of what React does internally
realDOM.querySelector('.card img').setAttribute('src', user.avatar);
realDOM.querySelector('.card h2').textContent = user.name;
realDOM.querySelector('.card p').textContent = user.bio;
// etc.The key insight: React does NOT touch the real DOM until it has fully computed the diff. All the expensive work (running component functions, comparing trees) happens in JavaScript memory. The real DOM is only updated with the minimal set of changes.
Phase 5: The Browser's Rendering Pipeline
Now the real DOM has been modified. The browser detects these changes and kicks off its own rendering pipeline. This is not controlled by React — it's the browser's built-in mechanism for turning DOM changes into pixels.Step 5a: Style Calculation
The browser takes the mutated DOM and matches every visible element against your CSS rules. It builds the CSSOM (CSS Object Model) — a tree of computed styles.
For our card, the browser figures out:
.card {
display: block;
border-radius: 8px;
box-shadow: 0 2px 8px rgba(0,0,0,0.1);
/* all other inherited & computed values */
}Every element gets a full set of computed styles. This is called "Recalculate Style" in DevTools.
Step 5b: Layout (Reflow)
The browser now calculates geometry — the exact position and size of every element on the page.
Starting from the <body>, the browser walks the render tree and figures out:
- How wide is .card? (depends on viewport and CSS)
- Where does the <img> go? What are its dimensions?
- How tall is the <h2> with this font size?
- Where does the button sit?
The browser produces a layout tree — every visible element now has x, y, width, height coordinates.
Layout is expensive. Changing something high up in the tree (like the body width) forces the browser to recalculate positions for everything below it. This is why CSS properties that trigger layout (width, height, padding, margin, top, left, etc.) are the ones you should change sparingly.Step 5c: Paint
Now the browser knows what to draw and where. It converts each layout box into actual pixels.
For each element, the browser draws:
- Background colors and images
- Borders and shadows
- Text glyphs
- Images (decoded from JPEG/PNG/WebP)
Painting happens on layers. The browser may split the page into multiple layers (for performance reasons — e.g., elements with position: fixed, transform: translateZ(0), or <video> get their own layer).Step 5d: Compositing
The browser takes all the painted layers and composites them together in the correct z-order. This is often done on the GPU, which is extremely fast at combining 2D textures.
For animations involving transform or opacity, the browser can skip Style and Layout entirely and just re-composite on the GPU. This is why React animations that use transform: translateX() instead of left: Xpx are much smoother.
Phase 6: User Interacts — The Cycle Repeats
The user clicks the heart button. Here's the full loop again:
1. Event fires — browser puts click event in the event loop
2. React event system — React's synthetic event handler intercepts it
3. setLiked(!liked) — React schedules a state update
4. Re-render — React calls ProfileCard again, gets new Virtual DOM
5. Diff — React compares old and new Virtual DOM
6. Commit — React updates the real DOM (changes the button text from 🤍 to ❤️)
7. Style — Browser recalculates styles for the button
8. Layout — Browser recalculates geometry (button text width changed, so position shifts slightly)
9. Paint — Browser repaints the affected pixels
10. Composite — GPU composites the final frame
All of this must happen in under 16.67ms (for 60fps) to feel smooth. If it takes longer, the user perceives "jank" — the button feels sluggish.
Why the Virtual DOM Exists: A Summary
Let's be precise about the Virtual DOM's purpose:Without React: You'd write button.textContent = '❤️'. The browser immediately starts its Style → Layout → Paint pipeline. If you made 10 changes in a row, the browser would run the pipeline 10 times. That's wasteful.With React: You call setLiked(true). React batches all changes, computes the minimal DOM mutations in JavaScript memory, and commits them all at once. The browser runs Style → Layout → Paint only once, with all changes applied simultaneously.
The Virtual DOM is not about being "faster than native DOM." It's about batching and intelligence — making the minimum necessary contact with the slow real DOM.
The Performance Bottlenecks, Simplified
1. Bundle Download — JS files travel over the network. React's control? Partial (code splitting helps). Impact: White screen.
2. JS Parse & Compile — V8 reads your bundle, turns it into bytecode. React's control? Partial (bundle size matters). Impact: Main thread blocked.
3. Render Phase (Virtual DOM) — React calls your component functions, builds the element tree. React's control? Full (React.memo, useMemo, React Compiler). Impact: Delayed interactivity.
4. Commit Phase — React writes changes to the real DOM (createElement, appendChild). React's control? Full (batching). Impact: Visual update.
5. Style & Layout — Browser calculates computed styles and element geometry. React's control? None (but your CSS choices affect it). Impact: Visual update.
6. Paint & Composite — Browser fills pixels and GPU assembles layers. React's control? None (but will-change/transform helps). Impact: Visual update.
Putting It All Together: A Timeline
When a user visits your React app for the first time, here's the chronological sequence:
0ms User types URL, hits Enter
5ms DNS lookup starts
50ms TCP + TLS handshakes
200ms Server responds with HTML (empty div#root)
220ms Browser starts parsing HTML
230ms Preload scanner finds <script> tag, starts downloading bundle
800ms Bundle finishes downloading (on fast connection)
820ms JavaScript parsing begins
950ms JavaScript parsing + compilation done
960ms ReactDOM.createRoot executes
965ms React calls App() → Navbar() → Sidebar() → ProfileCard()
970ms React commits to real DOM (div, img, h2, p, button created)
975ms Browser Style calculation begins
985ms Browser Layout begins
1000ms Browser Paint begins
1010ms First paint visible to user
1020ms Browser Composite finishes
1025ms User sees fully rendered card
The user waited ~1 second for a card with an image and some text. Most of that time was spent on things React has no control over: network, parsing, compilation, and the browser's rendering engine.
The part React does control — the render phase — took only about 10ms in this example.
The Real Takeaway
React is a DOM coordination layer, not a rendering engine. It doesn't paint pixels. It doesn't do layout. It doesn't decode images. All React does is manage the complexity of keeping your UI in sync with your state.
The journey from your ProfileCard component to the user seeing a card on screen involves:
1. Your build tool (Webpack) → JSX becomes JavaScript
2. The network → bundle arrives at the browser
3. V8/SpiderMonkey → JavaScript is parsed and compiled
4. React's reconciler → Virtual DOM is built and diffed
5. Browser's DOM API → mutations are applied
6. Browser's rendering engine → style, layout, paint, composite
Understanding this pipeline lets you make smart decisions: code split heavy routes, memoize expensive components, avoid layout-triggering CSS properties in animations, and use Concurrent React features to keep the main thread free for user interactions.Because at the end of the day, React is just JavaScript objects talking to the browser's pixel factory. If you understand both sides of that conversation, you win.