Skip to main content
Web DevRendering & FrontendDiagramBeginner

Virtual DOM

KO: 가상 DOM (Virtual DOM)·EN: Virtual DOM·JA: 仮想DOM(Virtual DOM)·VDOM

An in-memory JavaScript representation of the real DOM that diffs state changes and applies only minimal batched patches to the browser

Table of Contents

Structure Diagram

Virtual DOM Reconciliation & Minimal Patch Cycle
VIRTUAL DOM1. State Upd…2. Tree Diff…3. Minimal D…4. Browser P…
1/41. State Update
Build new VDOM tree
Quick Answer

What is Virtual DOM?

An in-memory JavaScript representation of the real DOM that diffs state changes and applies only minimal batched patches to the browser. It is a core concept in Rendering & Frontend within Web Dev.

Core Principles

Mutating the real browser DOM directly can trigger expensive style recalculations and layout reflows. A Virtual DOM (VDOM) keeps a lightweight JavaScript object tree representing the UI in memory.

Whenever state changes, the framework builds a new VDOM tree, diffs (reconciles) it against the previous tree using O(N) heuristics, and flushes only the minimal set of mutations to the real DOM. Its true advantage is enabling declarative UI programming with predictable, good-enough performance by default—not outperforming hand-tuned imperative DOM code in every micro-benchmark.

Practical Takeaways

  • Use stable, unique key props in lists: Using array indices as keys breaks reconciliation when items are inserted, reordered, or deleted, causing lost input focus and wasted DOM recreation.
  • Contain reconciliation scope: Diffing still consumes CPU cycles. Co-locate state close to where it is used and apply memoization selectively on expensive subtrees.
  • Know the trade-offs: Fine-grained reactive frameworks like SolidJS and Svelte skip the VDOM altogether by compiling state dependencies directly into targeted DOM updates.

Notable Examples

  • React Fiber: Breaks VDOM reconciliation into interruptible units of work so high-priority user inputs stay responsive.
  • Vue 3 Compiler-Informed VDOM: Hoists static subtrees and annotates dynamic bindings with patch flags to skip unchanged nodes during diffing.
  • Interactive SaaS dashboards: Keeps complex multi-pane interfaces synchronized with state without error-prone manual DOM queries.