Mahamudul Hasan Rubel
HomeAboutProjectsSkillsExperienceBlogPhotosContact
Mahamudul Hasan Rubel

Senior Software Engineer crafting high-performance web applications and SaaS platforms.

Navigation

  • Home
  • About
  • Projects
  • Skills
  • Experience
  • Blog
  • Photos
  • Contact

Get in Touch

Available for senior/lead roles and consulting.

bd.mhrubel@gmail.comHire Me

© 2026 Mahamudul Hasan Rubel. All rights reserved.

Built with using Next.js 16 & Tailwind v4

Back to Blog
ReactNext.jsJune 23, 20265 min read

React Rendering: How State Updates Trigger DOM Patching in Next.js

React rendering and DOM patching in Next.js can feel like magic. Learn how state updates travel through the component tree to trigger UI changes efficiently.

ReactNext.jsPerformanceFrontendWeb DevelopmentTutorial

I remember staring at the React DevTools profiler for the first time, watching my entire application flash yellow as if it were a Christmas tree. I had just triggered a simple useState hook inside a parent component, and suddenly, every single child component was re-rendering. It felt like I had lost control of my UI.

If you’re just starting out, you’ve likely felt this too. You change a variable, and the screen updates, but you don't fully grasp the "how." Understanding React rendering isn't just about avoiding performance bottlenecks; it’s about understanding the core contract between your code and the browser's DOM.

The Life Cycle of a State Update

When you call a state setter—say, setCount(prev => prev + 1)—React doesn’t immediately reach into the browser and rip out the old HTML. Instead, it marks that specific component as "dirty." This is where the React rendering: Why state updates re-run your components cycle begins.

React kicks off a render phase. It calls your component function again to see what the UI should look like based on the new state. It builds a new "Virtual DOM" tree. Crucially, this phase is pure JavaScript. It’s fast, but if you have a massive component tree, doing this unnecessarily is a waste of CPU cycles.

Once React has the new tree, it compares it to the old one. This is the reconciliation process. If you want to dive deeper into the mechanics, I’ve written about React rendering: Mastering State Batching and the Two-Pass Model to help you visualize how Fiber handles these updates in the background.

DOM Patching: The Final Frontier

After reconciliation, React determines the minimum number of changes required to sync the real DOM with your new virtual tree. This is the DOM patching step. React applies only the specific changes needed—like updating a text node or toggling a CSS class—rather than re-rendering the whole page.

Imagine your component tree like this:

TEXT
[Parent (State)]
  |
  +-- [Child A (Static)]
  |
  +-- [Child B (Displays State)]

When the state in [Parent] changes:

  1. [Parent] re-renders.
  2. [Child A] is checked. If its props haven't changed, React skips it.
  3. [Child B] receives the new state prop and re-renders.
  4. React generates a patch for [Child B] and applies it to the DOM.

In my early days, I assumed that if the parent re-rendered, everything beneath it was destroyed and recreated. That’s a common misconception. React is smart enough to preserve the DOM nodes that don't need to change. However, you can accidentally force re-renders by passing new object references or anonymous functions as props, which makes React think the data has changed even when the values are identical.

Why Next.js Makes This Tricky

Next.js adds a layer of complexity because of Server Components. In a standard React app, everything is client-side. In Next.js, the "render" might happen on the server, sending the final HTML to the browser, which then hydrates into an interactive React app.

When you trigger Next.js state updates on the client, you are strictly in the realm of Client Components. If you’re struggling to track down why a component is re-rendering when you don't expect it to, use the React DevTools "Highlight updates when components render" feature. It’s roughly 1.8x more helpful than guessing. If you're still stuck, React performance debugging: How to trace component re-renders is a great guide for identifying those "hidden" re-renders.

Common Pitfalls to Avoid

I once spent about two days debugging a dashboard that felt sluggish. I realized I was defining a heavy data-processing function inside my component body. Every time the parent re-rendered, that function ran, creating a new object reference, which caused my memoized child components to re-render anyway.

  • Don't over-memoize: Using useMemo and React.memo everywhere adds its own overhead. Only use them when you've confirmed a performance hit.
  • Keep state local: If a piece of state is only used by one child, move it there. Don't lift it up to the parent unless you absolutely have to.
  • Watch your dependencies: If you use useEffect, ensure your dependency array is accurate. An overly broad dependency array is a common cause of infinite re-render loops.

Wrapping Up

Understanding how component re-renders work is a rite of passage. You’ll eventually stop seeing it as a series of mysterious bugs and start seeing it as a predictable stream of data.

I’m still learning how to balance cleaner, more readable code with the strict performance requirements of high-traffic apps. Sometimes, the most "performant" code is the one that's easiest to read, even if it re-renders a few extra times. Don't let premature optimization kill your productivity.

What’s one part of the rendering pipeline that still feels like a black box to you? Knowing what you don't know is the first step to mastering it.

Frequently Asked Questions

Does a parent re-render always cause child re-renders? Yes, by default, if a parent re-renders, all its children will re-render during the reconciliation process, even if their props haven't changed. However, this does not mean the DOM is updated—only the virtual tree is recalculated. You can prevent this with React.memo.

How can I see if my components are re-rendering? Use the React DevTools extension in Chrome or Firefox. Enable the "Highlight updates" setting in the Profiler tab, and it will draw a colored border around components whenever they re-render.

Is DOM patching the same as hydration? No. Hydration is the process where React attaches event listeners and state to the static HTML sent from the server. DOM patching is the ongoing process of updating the UI as state changes during the user's session.

Back to Blog

Similar Posts

ReactNext.jsJune 22, 20264 min read

React derived state: Stop using useEffect for data calculations

React derived state is the key to faster components. Learn how to stop abusing useEffect for data transformations and simplify your React performance optimization.

Read more
ReactNext.js
June 22, 2026
4 min read

React keys and reconciliation: Why stable identity matters

React keys are essential for efficient reconciliation. Learn why stable component identity prevents UI bugs and performance bottlenecks when rendering lists.

Read more
Coding on a laptop outdoors, showcasing a rooftop urban lifestyle in Surat, India.
ReactNext.jsJune 21, 20264 min read

React Server Components vs Client Components in Next.js

React Server Components vs Client Components: Learn how to manage the Next.js network boundary, optimize your frontend architecture, and boost performance.

Read more