Open In App

ReactJS Reconciliation

React Reconciliation is the process through which React updates the Browser DOM. It makes the DOM updates faster in React. It updates the virtual DOM first and then uses the diffing algorithm to make efficient and optimized updates in the Real DOM.

React JS Reconciliation Working Concepts

The term rendering in React can closely be identified as making or becoming. In traditional rendering, the Browser does the following tasks:



This rendering by Browser has a sequence of steps and is rather costly in nature. The concept of Virtual DOM used by React makes rendering much faster.

Virtual DOM

React renders JSX components to the Browser DOM, but keeps a copy of the actual DOM to itself. This copy is the Virtual DOM. We can think of it as the twin brother of the real or Browser DOM. The following actions take place in React:



Fig.1: Calculating Diff and updating Browser DOM

Suppose we have new data similar to the previous one, Virtual DOM compares previous and new structures and sees that it has no change, so nothing gets rendered to the Browser. This is how the Virtual DOM is helping to enhance the Browser performance.

Diffing Algorithm

How does this Virtual DOM compare itself to its previous version?

This is where the Diffing Algorithm comes into play. Some concepts used by this Algorithm are:

  1. Two elements of different types will produce different trees.
  2. Breadth-First Search (BFS) is applied because if a node is found as changed, it will re-render the entire subtree hence Depth First Approach is not exactly optimal. (Ref: Fig.2)
  3. When comparing two elements of the same type, keep the underlying node as same and only update changes in attributes or styles.
  4. React uses optimizations so that a minimal difference can be calculated in O(N) efficiently using this Algorithm.

Fig.2: BFS for traversing Virtual DOM

Article Tags :