How React Works Under the Hood: A Deep Dive

View profile for Benson Chen

Senior Frontend Engineer | Ex-Trend Micro | Architected global checkout for 400K+ users across 30+ countries

⚛️ How React Actually Works Under the Hood React has become the dominant framework for UI rendering and logic control in modern frontend development, here is how it works. 🔄 1. React handle diffing calculation in the browser idle time Instead of blocking the main thread, React schedules work on idle time by using requestIdleCallback. (p.s. React use `scheduler` now for more aggressive works) During idle periods, React enters the render phase — running workLoop, which repeatedly calls performUnitOfWork to process small "units of work," which means building the Fiber tree element by element and diffing the current DOM. 🌲 2. Convert every Virtual DOM node into a Fiber React converts every virtual DOM element into a fiber node, which includes: · the EffectTag action to be taken on this element · the Link to represent the execution order on the fiber tree EffectTag: the future action to be taken on this element, like: · PLACEMENT ➜ Create a new DOM element · UPDATE ➜ Patch existing DOM · DELETION ➜ Remove outdated nodes Link: the connection between Fiber nodes, which represents the execution order on the fiber tree · Parent → First Child · Siblings → Next It’s React’s way of planning the DOM update before committing to the real DOM. 🏰 3. After the render phase, React commits to the real DOM Once all "unit of work" complete, React enters the commit phase, which means applying the change to the real DOM. Here, React traverses the fiber tree and applies changes to the real DOM based on each fiber’s effectTag. Here is the mini version of implementation: 👉 https://lnkd.in/gQucYcma #React #JavaScript #Frontend

  • How to build your own React

To view or add a comment, sign in

Explore content categories