<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Sumeet Dewangan on Medium]]></title>
        <description><![CDATA[Stories by Sumeet Dewangan on Medium]]></description>
        <link>https://medium.com/@sumeet-dewangan?source=rss-e3c58367c32d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*bzGq3FiElvxlwkSUZNL6PQ.jpeg</url>
            <title>Stories by Sumeet Dewangan on Medium</title>
            <link>https://medium.com/@sumeet-dewangan?source=rss-e3c58367c32d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 16 Nov 2026 23:13:48 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sumeet-dewangan/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[React Architecture — For Senior Engineers]]></title>
            <link>https://sumeet-dewangan.medium.com/react-architecture-for-senior-engineers-edc5720c4290?source=rss-e3c58367c32d------2</link>
            <guid isPermaLink="false">https://medium.com/p/edc5720c4290</guid>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[software-architecture]]></category>
            <dc:creator><![CDATA[Sumeet Dewangan]]></dc:creator>
            <pubDate>Mon, 05 Jan 2026 23:32:26 GMT</pubDate>
            <atom:updated>2026-01-06T07:57:17.655Z</atom:updated>
            <content:encoded><![CDATA[<h3>React Architecture — For Senior Engineers</h3><h4>React powers 40% of the web. But while most devs stop at hooks, Senior Engineers understand the Engine.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/516/1*iLIANSv3YYwajXkFw5mcog.png" /></figure><h3>Quick Refresher</h3><p>Let’s quickly re-iterate on some core concepts of React.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/773/1*5SBoWIf7EzlhGBdV62DdAg.png" /></figure><h3>How React Runs Code</h3><p>React is declarative. You tell what to render and React will figure out how to display it to the user.</p><p><strong>Phases:</strong></p><ol><li>Rendering — calculating what next of UI should look like</li><li>Effects are flushed — All effects are run, until none of them are left</li><li>React takes in new calculations, and compares it with Curren Tree</li><li>Commits the minimum changes to the DOM.</li><li>Run effects that are supposed to run after commit — such as useEffect.</li></ol><h3>V1: The Reconciliation Algorithm (deprecated)</h3><p>It’s the previous generation difference engine, used till React 15.</p><p>Takes 2 Virtual DOM trees, and find shortest path to match Browser real DOM to match new one. Uses heuristic assumptions to keep comparisons fast. O(n³) → O(n).</p><h4><strong>Core Ideas:</strong></h4><ol><li>Different elements → different trees → re-render</li><li>Developer can hint which child elements are stable across renders using key. Remember, the keys that you provide in loops.</li></ol><h4>Element Diffing (Tear Down vs Update)</h4><p>Looks at the root of change</p><ol><li>&lt;div&gt; -&gt; &lt;span&gt;: different elements - replaces the old element with new one, destroying its state</li><li>&lt;div className=”before&quot;&gt; -&gt; &lt;div className=”after&quot;&gt;: smart check , applies new attributes</li></ol><h4><strong>Rendering Child Components with “key”</strong></h4><p>A component with multiple child components generated dynamically faces rendering issues. A single change in ordering would trigger repaint</p><p><strong>Problem: </strong>React has no way to identify if the parent has same set of same components, or different or is it just reordered.</p><p><strong>Solution</strong>: Assign unique keys to child component in list</p><h4>Problem with Reconciliation</h4><ol><li>Recursive. Cannot stop unless an update is made</li><li>May freeze browser for large virtual DOMs</li></ol><h3>V2: Introducing - React Fiber (16+)</h3><blockquote><em>💡</em>Engine under the hood of React. Written from ground-up, replacing Reconciliation Algorithm.</blockquote><p>Released in React 16, and fully realized with Concurrent Mode in 2020. <strong>Replaced the recursive update function to Linked List of objects, allow pause and scheduling.</strong></p><h4>Solution to Reconciliation</h4><p>Introduced in 2017, perfected in modern versions. Switches Approach: Recursive → linked list</p><p><strong>Principles</strong></p><ol><li>Pause work for a high priority event (like input)</li><li>Prioritize work — ex: handling input is more imp. than updating chart</li><li>Discard work: If a new update comes in middle, discard old work</li></ol><h4>Internals of Fiber</h4><p><strong>Fiber Node:</strong> Simple JS object, representing unit of work. Key Properties:</p><ol><li>type and key — identify the document</li><li>child, sibling and return — these form the link list node. return points to the parent</li><li>pendingProps vs memoizedProps — helps identify if component needs re-rendering</li><li>alternate — reference to the other of node, in the different Virtual DOM tree</li><li>lanes — bitmask to represent the priority of update</li></ol><h4>How it works: The Two-Phase Process</h4><p><strong>Phase #1: Render / Reconciliation (Interruptable)</strong></p><ol><li>Builds “Work-in-progress” tree.</li><li>React uses linked list to apply updates.</li><li>React looks at browser clock, and if frame is about to end, it yields back the control to browser.</li><li>Once browser is idle, it continues from where it left off, using the alternate, and child/sibling pointer</li></ol><p><em>This phase is pure — absolutely No DOM changes</em></p><p><strong>Phase #2: Commit (Synchronous / Non Interruptable)</strong></p><p>Applies all changes to dom updates from Work in progress tree</p><h4><strong>Pros of React Fiber</strong></h4><ol><li><strong>Concurrency.</strong> Enables features like:</li></ol><ul><li>Suspense (waiting for data).</li><li>useTransition for low priority UI updates. This prevents Jank on Low End DevicesSuspense (waiting for data).</li><li>useTransition for low priority UI updates. This prevents Jank on Low End Devices.</li></ul><p>2. <strong>Main thread is never blocked</strong> for more than a few ms.</p><p>3. <strong>Error Boundaries: </strong>Granular Work allows catching error in one node, while still rendering the rest of tree.</p><h4>Some Downsides of React Fiber</h4><ol><li><strong>Memory Overhead:</strong> Too much data to maintain — 2 trees + fiber nodes containing child, sibling and return ptrs.</li><li><strong>Runtime Cost:</strong> Every update requires VDOM diff, making it slow in Number Crunching.</li><li><strong>Double Reader Confusion:</strong> A component can be updated multiple times, before it is rendered. So, side-effects like API calls must be used under useEffect.</li></ol><h3>Scheduler (React 18+)</h3><blockquote>💡Handles prioritization logic in React. Add interruptibility to the system, and helps provide perceived performance.</blockquote><h4>The thought behind Scheduler..</h4><ol><li>React categorizes every update with a Priority Level.</li><li>Helps achieve 60fps (16ms) response time.</li></ol><p>Not every event is equally prioritized. For ex:</p><ol><li><strong>Immediate Priority:</strong> Synchronous tasks that must run now.</li><li><strong>User Blocking Priority:</strong> User input, tab button clicks or other such synchronous events.</li><li><strong>Normal Priority:</strong> Data Fetching (doesnt need to be instant)</li><li><strong>Low Priority:</strong> Prefetching data — i.e. Background Tasks</li><li><strong>Idle Priority:</strong> Logs, analytics — basically tasks that can wait indefinitely</li></ol><h4>How Scheduler Works?</h4><p>Uses technique called <strong>Time Slicing.</strong></p><ol><li>Starts working on Normal Priority Ops, like rendering 5000 items.</li><li>Yields the control back to browser after doing so for a few ms.</li><li>User types something in browser → scheduler sees a User Blocking Priority event.</li><li>React pauses rendering, save state to memory, and handles the inputs.</li><li>Resumes the list rendering, when the user inputs are handled.</li></ol><h4>Quick Example</h4><p>User types in search box, with massive result list. Filtering a single input in the list takes 200ms.</p><ul><li>Earlier: If filtering a single input takes 200ms, then entire UI looks laggy.</li><li>Now: Implement useTransition hook, which tells React which part of the app is high/low priority.</li></ul><pre>const [isPending, startTransition] = useTransition();<br><br>// 1. High Priority: Update what the user sees in the box immediately<br>setInputValue(nextValue);<br><br>// 2. Low Priority: Wrap the heavy filtering in a transition<br>startTransition(() =&gt; {<br>  setFilteredList(hugeData.filter(item =&gt; item.includes(nextValue)));<br>});</pre><p>In the above code:</p><ol><li>Input is immediately rendered.</li><li>React works on filtering in background.</li><li>User updates the input → React abandons the previous calculations and does the new calc.</li></ol><h3>React Compiler (React Forget) — React 19+</h3><p><em>Build time tool. Makes React Code “auto-memoized”. </em>Gives fine-grained performance, without changing React programming model.</p><p>The compiler treats code as a <strong>Dependency Graph. </strong>Instead of you telling React <em>“memoize this function”</em>, the compiler says <em>“I see function is passed to UserList; I will ensure its reference only changes if the data it captures changes”</em>.</p><h4>Thought behind React Compiler..</h4><p>React was “coarse-grained”. State change in component, entire function re-ran resulting in re-rendering all the children components. For this, React.memo, useMemo or useCallback was introduced.</p><p>This created 3 problems:</p><ol><li><strong>Developer Experience:</strong> Developers had to litter code with dependency array [prop1, prop2]. Missing one gave stale closure bug 🐛.</li><li><strong>Performance:</strong> No memoization — slow app, too much memoization — complicated codebase.</li><li><strong>Context Hell:</strong> Context Provider Updates → All consuming components re-renders.</li></ol><p>Example of useMemoto prevent expensive component from rerendering everytime user input changed.</p><pre>function App() {<br>  const [text, setText] = useState(&quot;&quot;);<br>  const [count, setCount] = useState(0);<br><br>  // Manually memoizing to prevent re-calculation on &#39;text&#39; change<br>  const doubledCount = useMemo(() =&gt; count * 2, [count]);<br><br>  return (<br>    &lt;div&gt;<br>      &lt;input value={text} onChange={(e) =&gt; setText(e.target.value)} /&gt;<br>      &lt;ExpensiveComponent value={doubledCount} /&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><h4>How React Compiler works?</h4><ol><li>Compiler works with Babel/Build step.</li><li>Parses component logic and identifies which values are derived from which inputs.</li><li>We write “Vanilla React”. The React Compiler effectively re-writes the code to look like reactive graph.</li><li>Compiler treats every variable and function as if it were wrapped in useMemo or useCallback by default</li></ol><p>When the React Compiler processes your code, it injects a “memo cache” (often referred to as the `$`) to store results. Here’s an example, with source code and how React Compiler transforms it.</p><pre>function SearchList({ items, query }) {<br>  const filtered = items.filter(i =&gt; i.includes(query));<br>  return &lt;ul&gt;{filtered.map(i =&gt; &lt;li key={i}&gt;{i}&lt;/li&gt;)}&lt;/ul&gt;;<br>}</pre><p>React Compiler injects a “memo cache” (often referred to as the $) to store results. Here is how a simple component is transformed:</p><pre>function SearchList(t0) {<br>  const { items, query } = t0;<br>  const $ = useMemoCache(4); // Internal React hook for caching<br>  <br>  // Check if &#39;items&#39; or &#39;query&#39; changed since last time<br>  let t1;<br>  if ($[0] !== items || $[1] !== query) {<br>    t1 = items.filter(i =&gt; i.includes(query));<br>    $[0] = items;<br>    $[1] = query;<br>    $[2] = t1;<br>  } else {<br>    t1 = $[2]; // Return cached filtered list<br>  }<br>  <br>  // Same logic for the JSX...<br>  let t2;<br>  if ($[3] !== t1) {<br>    t2 = &lt;ul&gt;{t1.map(i =&gt; &lt;li key={i}&gt;{i}&lt;/li&gt;)}&lt;/ul&gt;;<br>    $[3] = t2;<br>  } else {<br>    t2 = $[3];<br>  }<br>  return t2;<br>}</pre><h4>Under the hood..</h4><p>React Compiler transforms your code, to a code that checks…</p><pre>if (dependencies_changed) { recalculate } else { use_cached_value }</pre><p><strong>How React Compiler removes </strong><strong>useMemo?</strong></p><p>With react compiler, you can eliminate the entire useMemo hook, like…</p><pre>function App() {<br>  const [text, setText] = useState(&quot;&quot;);<br>  const [count, setCount] = useState(0);<br><br>  // No useMemo needed!<br>  const doubledCount = count * 2; <br><br>  return (<br>    &lt;div&gt;<br>      &lt;input value={text} onChange={(e) =&gt; setText(e.target.value)} /&gt;<br>      &lt;ExpensiveComponent value={doubledCount} /&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><p><strong>How React Compiler removes </strong><strong>useCallback ?</strong></p><p>Functions are recreated on every render. This cause child components wrapped in React.memo to break because the function ref is “new”.</p><ul><li>Old way: Wrap functions in useCallback(fn, [&lt;dependencies&gt;]).</li><li>Compiler way: The compiler detects if variables in function closure changed. If same — preserves fn reference, else creates a new fn.</li></ul><h4>Use Cases Solved</h4><ol><li><strong>Context Hell:</strong> Context Provider updates now only affects the components that use the changed parts.</li><li><strong>Auto memoization</strong> — allows adding 1 item to list, without causing rerender of the other elements of a large list.</li><li><strong>Derived State:</strong> Calculations like sorting/filtering a list are now memoized, without developer thinking about it.</li><li><strong>Eliminates referential cascades:</strong> One missing useCallback at top level could trigger entire tree to re-render. i.e. parent → child → grandchild.</li><li><strong>Adds code consistency</strong>. Helps focus on logic and not plumbing.</li></ol><p>That wraps up “The React Architecture”. For more such bite-sized articles designed for Senior Engineers, follow me.</p><p>Do checkout my other posts: <a href="https://medium.com/@sumeet-dewangan">https://medium.com/@sumeet-dewangan</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=edc5720c4290" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>