惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
T
The Exploit Database - CXSecurity.com
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Spread Privacy
Spread Privacy
Hacker News - Newest:
Hacker News - Newest: "LLM"
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Google Online Security Blog
Google Online Security Blog
S
Security Affairs
Help Net Security
Help Net Security
Simon Willison's Weblog
Simon Willison's Weblog
N
News and Events Feed by Topic
P
Palo Alto Networks Blog
P
Privacy International News Feed
T
Threat Research - Cisco Blogs
P
Proofpoint News Feed
N
News and Events Feed by Topic
C
Cyber Attacks, Cyber Crime and Cyber Security
TaoSecurity Blog
TaoSecurity Blog
T
Tor Project blog
Schneier on Security
Schneier on Security
WordPress大学
WordPress大学
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
V
Visual Studio Blog
F
Fortinet All Blogs
大猫的无限游戏
大猫的无限游戏
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
T
Tenable Blog
M
MIT News - Artificial intelligence
T
Threatpost
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
N
News | PayPal Newsroom
P
Privacy & Cybersecurity Law Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
Microsoft Azure Blog
Microsoft Azure Blog
小众软件
小众软件
Cyberwarzone
Cyberwarzone
雷峰网
雷峰网
云风的 BLOG
云风的 BLOG
量子位
Google DeepMind News
Google DeepMind News
O
OpenAI News
爱范儿
爱范儿
H
Hackread – Cybersecurity News, Data Breaches, AI and More
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
F
Full Disclosure
B
Blog
Cloudbric
Cloudbric
MyScale Blog
MyScale Blog
阮一峰的网络日志
阮一峰的网络日志

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant Common SOC 2 Failures (Real World) Stop Vibe-Checking Your AI App: A Practical Guide to Evals How to Use SonarQube and SonarScanner Locally to Level Up Your Code Quality Your Next To-Do App Is Dead — I Replaced Mine with an OpenClaw AI Sign a Nostr event in 60 lines of Python using coincurve — no nostr-sdk, no nbxplorer, no rust toolchain ITGC Audit Explained Like You’re in Big 4 Patch Tuesday abril 2026: Microsoft parcha 163 vulnerabilidades y un zero-day en SharePoint Stop scraping everything: a better way to track competitor price changes Listing on MCPize + the Official MCP Registry while routing payments OUTSIDE the marketplace — how I kept 100% of my x402 revenue Building an AI-Powered Risk Intelligence System Using Serverless Architecture Why We Ripped Function Overloading Out of Our AI Toolchain Testing AI-Generated Code: How to Actually Know If It Works SaaS Churn Is Killing Your Business. Here Is What to Do About It (Without a Support Team) The Speed of AI Is No Longer Linear - And Self-Improving Models Are Why How to Implement RBAC for MCP Tools: A Practical Guide for Engineering Teams From Standard Quote to Persuasive Proposal: AI Automation for Arborists I built a CLI that scaffolds complete multi-tenant SaaS apps Axios CVE-2025–62718: The Silent SSRF Bug That Could Be Hiding in Your Node.js App Right Now The dashboard that ended our friendship Data Pipelines Explained Simply (and How to Build Them with Python) The Hidden Cost of AI Systems Nobody Talks About. undefined vs undeclared, and how typeof behaves Switching from file-based jobs to NATS/Kafka in Rust without changing code io_uring Adventures: Rust Servers That Love Syscalls Why Agentic AI is Killing the Traditional Database The POUR principles of web accessibility for developers and designers Quantum Neural Network 3D — A Deep Dive into Interactive WebGL Visualization How To Install Caveman In Codex On macOS And Windows Automation Pipeline Reliability: Why Your Workflow Breaks When Nobody Is Watching I Built an 'Open World' AI Coding Agent — It Works From ANY Folder From Freelancing to Product: A Tech Service Company's SaaS Transformation China's AI Giants: Adding Tencent Hunyuan & ByteDance Doubao to AI University (74 Providers) On the Vibe Coders and Their Lies clerk: Auto-Summarize Your Claude Code Sessions AI Weekly — 2026/04/10–04/17 | The Model Lockdown Is Here, but the Toolchain Is the Real Battleground AI 週報 — 2026/04/10–2026/04/17 模型封鎖潮來了,但工具鏈才是真戰場 Maybe this is how Open-Source apps are born... 🚀 Fine-Tune LLMs with LoRA and QLoRA: 2026 Guide tRPC v11 + Next.js App Router: End-to-End Type Safety Without the Boilerplate ShadCN UI in 2026: Why I Stopped Installing Component Libraries and Started Owning My Components SaaS Billing in React Server Components: Stripe + Supabase Without a Single `useEffect` Join our DEV Weekend Challenge — $1,000 in Prizes Across TEN winners! Submissions Due April 20 at 6:59 AM UTC. Implementing FSRS Spaced Repetition in Flutter + Supabase — Adding Memory Science to an AI Learning App "I Texted My Localhost From the Train — Claude Code Fixed the Bug Before I Got Home" I Built a Sales Prep AI and It Went Deeper Than Expected Design to Code #2: One JSON, Eleven Outputs Solving the 100M-Row Problem: A Summary Table Pattern for High-Volume Push Notification Logs Flutter Web With Wasm: What Actually Changes For Developers I Built 50 Royalty-Free Soundtracks for My Side Project in a Weekend Using AI Music Generation The Vibe Coding Security Checklist: 7 Things to Check Before You Ship Stop Letting Googlebot Guess Fix Your React App's SEO Right Desconstruindo o Streaming do LinkedIn: Como Criar um Engine de Extração de Vídeo de Alta Performance com HLS e FFmpeg (EDA Part-1) EDA (Exploratory Data Analysis) Explained With Real Life — Why Looking at Your Data Is the Most Important Step in Machine Learning Brand Relationship Management at Scale: Our 4-Touch Outreach System for 200+ Brands Why String.fromEnvironment() Might Return an Empty String in Dart JGuardrails 1.0.0 — Hardening Java LLM Apps Against Jailbreaks, Toxicity, and Prompt Injection Plan and Schedule a Full Week of Threads Content From One Claude Conversation Coding Cat Oran Ep3, Five Tables Changed Everything Updated: BFF Pattern I'm done watching freelancers get buried by 200 proposals. So I'm building the alternative. This is my first post BFS Algorithm in Java Step by Step Tutorial with Examples Tracking LLM Pricing Monthly: An Open Dataset for 22 AI Models How We Measure Content ROI on a Comparison Site: Revenue Attribution Without Perfect Data Introducing Nova AI Ops: The AI-Native Operating System for SRE Teams I built a free desktop video downloader for Windows — Grabbit How Talkie OCR Helps Vision-Impaired & Dyslexic Users Read the World Around Them VRCFaceTracking安装和iPhone面捕配置教程,有bug Even CrowdStrike Can't See Your Agents The Automation Gold Rush: What n8n Workflows and Claude Are Opening Up for Developers Right Now
Understanding React Virtual DOM Internally
Shivam Yadav · 2026-05-06 · via DEV Community

hey reader its me shivam

and today i am all researching about DOM and how React works, why am i learning it, what benefit do i get after learning it

so with this many thoughts i really got to know about what is Virtual DOM and how things internally work in React

so i am not going to bore u or anything so lets start


First let see the problem statement

so population is growing ( people are doing too much sex )

as well the user of web has also grown

and in web application there is constant changes happening like:

  • notification
  • message loading
  • forms validation
  • comments
  • likes
  • realtime updates

etc

if browser update the page directly for every changes the application would become slow and kinda heavy

this is exactly the problem faced by facebook developer

so they created REACT and react's virtual DOM was designed to solve this problem

now this was the story for React that u have heard many time

now lets start understanding of REACT working


The Problem : Direct DOM Manipulation is Expensive

before understanding Virtual DOM, first lets understand Real DOM


what is real DOM

the real DOM is the browser tree structure representing the HTML in element

Example:

<div>
  <h1>Hello</h1>
  <button>Click</button>
</div>

Enter fullscreen mode Exit fullscreen mode

Browser converts this into a tree-like structure:

div
 ├── h1
 └── button

Enter fullscreen mode Exit fullscreen mode

The browser basically create a tree from your HTML

and every single element becomes a node inside memory

the issue is:

updating the real DOM is Expensive ( now this sound out of the box but it is Expensive )

things like:

  • repainting
  • reflow
  • layout recalculation
  • css recalculation

Even changing a small thing in HTML can cause heavy loading

see for example there are 100's of node/html element now u want to add one more element at 98

now what browser DOM will do?

he will just reload everything create a new DOM tree and while creating it will add the new added element at 98'th place

as u can see the unnecessary loading of all 97 element is doing

parsing of HTML, then css calculation, applying

it sound heavy then imagine the actual implementation

and yes browser is fast...

but modern UI are even faster 💀


this is where React enters into the picture

imagine a social media feed

every second:

  • likes increase
  • message arrive
  • notification popup
  • comments loading

are happening now with each updating, performance would collapse

React solve this by:

  1. creating a Virtual DOM tree
  2. comparing changes effectively
  3. updating only changed node

yes i know sound technical but lets see something here


What is Virtual DOM?

As the name implies, the Virtual DOM is a much lighter replica of the actual DOM in the form of objects.

it is basically a lightweight JavaScript representation of UI

this is how the object looks like

{
  type: "div",
  props: {
    children: [
      {
        type: "h1",
        props: {
          children: "Hello"
        }
      }
    ]
  }
}

Enter fullscreen mode Exit fullscreen mode

The virtual DOM can be saved in the browser memory and doesn’t directly change what is shown on the user’s browser.

Implemented by several other frontend frameworks, like Vue, React’s declarative approach is unique.

this is the cool part

nothing is directly touching the browser DOM instantly

React first prepares everything virtually

like writing rough work before final answer 😭


this is what React do ( Master React )

if u understand this u will get almost 90% of React working

React is working in three stages


1) Rendering

when ever a component state or props changes, React re-render the component UI to generate a new Virtual DOM tree

this tree is kinda representation of UI component in plain JavaScript object

it is kinda same as browser DOM but omitting the browser detail

kinda help being fast

things to be known:

there are three DOM now

  1. the previous Virtual DOM
  2. the new updated Virtual DOM
  3. the actual browser DOM

2) Diffing

once the new Virtual DOM is created now React perform the diffing process

it start comparing the new tree with the previous version to identify exactly which element have changed

in short it find out diff between new and old Virtual DOM

the comparison matches element types using keys and list item helps on quickly pinpointing changes

now it will only isolate the difference, significantly minimizing the number of update needed


Example of Diffing

Old tree:

<h1>0</h1>

Enter fullscreen mode Exit fullscreen mode

New tree:

<h1>1</h1>

Enter fullscreen mode Exit fullscreen mode

React notices:

  • h1 tag is same
  • Only text changed

So React updates only text content.

Minimal Real DOM Update

Instead of rebuilding everything:

<h1>0</h1>

Enter fullscreen mode Exit fullscreen mode

becomes:

<h1>1</h1>

Enter fullscreen mode Exit fullscreen mode

Only the changed node updates.

This is the key optimization.


Diagram : Diffing Process

Old Virtual DOM
      ↓
Compare
      ↓
New Virtual DOM
      ↓
Find Difference
      ↓
Update Only Changed Node

Enter fullscreen mode Exit fullscreen mode

things to be known:

  1. this process is also called reconciliation
  2. in simple words it does comparing two Virtual DOM trees to find what changed

some people think Virtual DOM itself is the magic

but actually reconciliation is the real beast behind React 😭

Virtual DOM is just the data structure

reconciliation is the brain


3) Patching

so now after knowing the changes React generate a minimal instruction and applies the changes to the actual DOM

this process is known as patching

things to be known:

  1. it is also known as commit phase

instead of re-rendering the entire DOM tree, only the modified parts are updated

help in reducing performance overhead with full DOM updates

and this is why React apps feel smooth most of the time

unless u forgot dependency array in useEffect

then may god help your CPU 💀


NOW lets deep dive in more of rendering

How re-rendering impacts performance

DOM operations are very fast, light operations.

However, when the app data changes and triggers an update, re-rendering can be expensive.

Let’s simulate re-rendering a page with the JavaScript code below:

const update = () => {
 const element = `
  <h3>JavaScript:</h3>
  <form>
   <input type="text"/>
  </form>
  <span>Time: ${new Date().toLocaleTimeString()}</span>
 `;

 document.getElementById("root1").innerHTML = element;
};

setInterval(update, 1000);

Enter fullscreen mode Exit fullscreen mode

The DOM tree representing the document looks like the following:

now this setInterval() callback is triggering the rendering in each second as can see in the GIF

so basically the DOM element are getting rebuild and painted on each update(second)

and the text input in UI also loses its state due to the re-render

soo as u can see the problem clearly like really clearly

when ever the UI update the things written on input is getting wiped out like it was never there

basically the state is getting changed

so to solve this problem different JS framework provide different solution

React implement the concept of the Virtual DOM

As the name implies, the virtual DOM is a much lighter replica of the actual DOM in the form of objects.

this is how the object looks like

The virtual DOM can be saved in the browser memory and doesn’t directly change what is shown on the user’s browser.


how React implement the Virtual DOM

To understand the Virtual DOM strategy, we need to understand the two major phases that are involved:

  • rendering
  • reconciliation

When we render an application UI, React creates a Virtual DOM tree representing that UI and stores it in memory.

On the next update, or in other words, when the data that renders the app changes, React will automatically create a new Virtual DOM tree for the update.

To further explain this, we can visually represent the Virtual DOM as follows:

The image on the left is the initial render.

As the Time changes, React creates a new tree with the updated node, as seen on the right side.

Remember:

the Virtual DOM is just an object representing the UI

so nothing gets drawn on the screen directly.

After React creates the new Virtual DOM tree, it compares it to the previous snapshot using a diffing algorithm called reconciliation to figure out what changes are necessary.

After the reconciliation process, React uses a renderer library like ReactDOM, which takes the different information to update the rendered app.

This library ensures that the actual DOM only receives and repaints the updated node or nodes.

As seen in the image above, only the node whose data changes gets repainted in the actual DOM.

The GIF below further proves this statement:


The React Diffing Process

When React diffs two Virtual DOM trees, it begins by comparing whether or not both snapshots have the same root element.

If they have the same elements, like in our case where the updated nodes are of the same span element type, React moves on and checks the attributes.

If attributes are same then React moves deeper into child nodes.

Upon seeing that the Time text node has changed, React will only update the actual node in the real DOM.


Different Element Type Case

if both snapshots have different element types, React will destroy the old DOM nodes and build a new one.

For instance:

<span>Time: 04:36:35</span>

Enter fullscreen mode Exit fullscreen mode

becomes

<div>Time: 04:36:38</div>

Enter fullscreen mode Exit fullscreen mode

now React cannot optimize this because the element type itself changed

so React rebuilds that section


Example using React State

import { useState } from "react";

const App = () => {
 const [open, setOpen] = useState(false);

 return (
  <div className="App">
   <button onClick={() => setOpen((prev) => !prev)}>toggle</button>

   <div className={open ? "open" : "close"}>
    I'm {open ? "opened" : "closed"}
   </div>
  </div>
 );
};

export default App;

Enter fullscreen mode Exit fullscreen mode

Updating the component state re-renders the component.

However, as shown below, on every re-render, React knows only to update:

  • the class name
  • the text that changed

This update will not hurt unaffected elements in the render.

and this is why React feel smooth

otherwise every button click would feel like windows XP restarting 😭


How React Diffs Lists

When we modify a list of items, how React diffs the list depends on whether the items are added at the beginning or the end of the list.

Consider this list:

<ul>
  <li>item 3</li>
  <li>item 4</li>
  <li>item 5</li>
</ul>

Enter fullscreen mode Exit fullscreen mode

On the next update, lets append an item 6 at the end:

<ul>
  <li>item 3</li>
  <li>item 4</li>
  <li>item 5</li>
  <li>item 6</li>
</ul>

Enter fullscreen mode Exit fullscreen mode

React compares the items from the top.

It matches:

  • item 3
  • item 4
  • item 5

and only insert item 6

This computation is straightforward for React.

easy work for React


But now comes the real issue

what if we prepend item 2?

<ul>
  <li>item 2</li>
  <li>item 3</li>
  <li>item 4</li>
  <li>item 5</li>
</ul>

Enter fullscreen mode Exit fullscreen mode

Similarly, React compares from the top, and immediately realizes that item 3 doesn’t match item 2 of the updated tree.

now React compares from top and sees:

item 3 ≠ item 2

Enter fullscreen mode Exit fullscreen mode

so React think:

"bro everything changed 💀"

and it may rebuild the whole list


This is why React Keys Matter

Instead of rebuilding the entire list, we want the DOM to compute minimal operations by only prepending item 2.

React lets us add a key prop to uniquely identify items.

<ul>
  <li key="3">item 3</li>
  <li key="4">item 4</li>
  <li key="5">item 5</li>
</ul>

<ul>
  <li key="2">item 2</li>
  <li key="3">item 3</li>
  <li key="4">item 4</li>
  <li key="5">item 5</li>
  <li key="6">item 6</li>
</ul>

Enter fullscreen mode Exit fullscreen mode

With keys, React understands:

  • item 2 is new
  • item 6 is new
  • existing items are same

As a result, it would work to preserve the items that are already available and add only the new items in the DOM.

so only minimal updates happen

this is why senior developers scream:

"PUT KEYS IN LIST"

now u know why 😭


How is Virtual DOM Different from Real DOM?

A common misconception is that the Virtual DOM is faster than or rivals the actual DOM.

However, this is untrue.

In fact, the Virtual DOM’s operations support and add on to those of the actual DOM.

Essentially, the Virtual DOM provides a mechanism that allows the actual DOM to compute minimal DOM operations when re-rendering the UI.

For example, when an element in the real DOM is changed, the DOM will re-render the element and all of its children.

When it comes to building complex web applications with a lot of interactivity and state changes, this approach is slow and inefficient.

Instead, in the rendering process, React employs the concept of the Virtual DOM, which conforms with its declarative approach.

Therefore, we can specify what state we want the UI to be in, after which React makes it happen.

After the virtual DOM is updated, React compares it to a snapshot of the virtual DOM taken just before the update, determines what element was changed, and then updates only that element on the real DOM.

This is one method the Virtual DOM employs to optimize performance.

Real DOM Virtual DOM
Heavy Lightweight
Direct browser updates JS object
Expensive updates Efficient diffing
Causes repaint/reflow Minimal updates
Hard manual manipulation Declarative updates

The Virtual DOM abstracts manual DOM manipulations away from the developer, helping us write more predictable code so that we can focus on creating components.

Thanks to the Virtual DOM, you don’t have to worry about state transitions.

Once you update the state, React ensures that the DOM matches that state.

For instance, in our last example, React ensures that on every re-render, only Time gets updated in the actual DOM.

Therefore, we won’t lose the value of the input field while the UI update happens.


Fun Fact : Virtual DOM Isn’t Always the Fastest

I know, bold statement.

But sometimes manual DOM updates are faster, especially for static-heavy pages.

Libraries like Svelte skip the Virtual DOM altogether, compiling updates directly to the DOM at build time.

React trades a bit of raw speed for:

  • developer happiness
  • maintainability
  • scalability

And lets be honest

we love that.


Think of Virtual DOM Like a Draft System

Think of the Virtual DOM as your favorite todo app.

You write down what changed.

Then review and edit before committing.

Only after reviewing, you update the real list.

Same with React.

  • Draft first (Virtual DOM)
  • Diff and plan (reconciliation)
  • Then update reality (Real DOM)

The Virtual DOM is often credited for React’s speed, but the real hero behind the scenes is reconciliation.

it’s what determines:

  • what to update
  • when to update
  • how to sync efficiently

A poor reconciliation strategy can significantly impact your app’s performance.


in the end

is it really fast?

i asked this from my senior and he said at initial level u will see it as just extra working:

  • rendering
  • diffing
  • patching

but when we start talking about millions of nodes handling then the magic of React appears

at small level u might not notice the difference much

but at scale?

that architecture matters a lot

and that all from my side

if u find this blog interesting and knowledgeable please feel free to drop a like and comment down what can be better

i am really in need of improving

bye

see u in the next blog

till then bye bye