<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: frontend.rocks</title>
    <description>The latest articles on DEV Community by frontend.rocks (@frontend_rocks).</description>
    <link>https://dev.to/frontend_rocks</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F96346%2F8a8f07c2-7914-4d19-9fb2-1631df84163b.jpg</url>
      <title>DEV Community: frontend.rocks</title>
      <link>https://dev.to/frontend_rocks</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/frontend_rocks"/>
    <language>en</language>
    <item>
      <title>Autopsy #03: Why One Click Triggers 14 Re-Renders and a Layout Shift</title>
      <dc:creator>frontend.rocks</dc:creator>
      <pubDate>Tue, 17 Nov 2026 16:30:00 +0000</pubDate>
      <link>https://dev.to/frontend_rocks/autopsy-03-why-one-click-triggers-14-re-renders-and-a-layout-shift-47da</link>
      <guid>https://dev.to/frontend_rocks/autopsy-03-why-one-click-triggers-14-re-renders-and-a-layout-shift-47da</guid>
      <description>&lt;h2&gt;
  
  
  Incident Report
&lt;/h2&gt;

&lt;p&gt;A design-system polish PR added a compact-density toggle to the catalog filter bar, updating &lt;code&gt;--row-density&lt;/code&gt; on &lt;code&gt;:root&lt;/code&gt; and equalizing row heights in &lt;code&gt;useLayoutEffect&lt;/code&gt;. On an M3 MacBook Pro with 20 test items, the toggle felt instantaneous.&lt;/p&gt;

&lt;p&gt;On production catalog pages with 2,400 DOM nodes, Core Web Vitals telemetry flagged an immediate Interaction to Next Paint (INP) and Cumulative Layout Shift (CLS) regression.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;T+00:00&lt;/strong&gt;: Filter density feature ships to 100% of catalog traffic.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;T+15:00&lt;/strong&gt;: RUM p75 INP jumps from 38 ms to 180 ms on mid-tier Android devices.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;T+25:00&lt;/strong&gt;: CLS spikes to 0.14 as the sticky toolbar drops 24 px downward on every filter click.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;T+40:00&lt;/strong&gt;: DevTools Performance traces capture a 180 ms Long Task containing 14 React commit phases and 14 purple &lt;code&gt;Layout&lt;/code&gt; bars per click.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The Red Herring
&lt;/h2&gt;

&lt;p&gt;In Slack, the team immediately wrapped &lt;code&gt;&amp;lt;CatalogGrid&amp;gt;&lt;/code&gt; in &lt;code&gt;React.memo&lt;/code&gt; and pushed a hotfix. Local unit tests confirmed &lt;code&gt;&amp;lt;CatalogGrid&amp;gt;&lt;/code&gt; skipped renders when unrelated props stayed equal.&lt;/p&gt;

&lt;p&gt;In production, &lt;code&gt;React.memo&lt;/code&gt; saved zero milliseconds. Every click mutated a root CSS variable, recreated the parent context &lt;code&gt;value={{ filter, density }}&lt;/code&gt; object literal, and interleaved &lt;code&gt;getBoundingClientRect()&lt;/code&gt; reads with &lt;code&gt;style.minHeight&lt;/code&gt; writes inside &lt;code&gt;useLayoutEffect&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Causal Chain
&lt;/h2&gt;

&lt;p&gt;One click cascades through five rendering layers. A &lt;code&gt;:root&lt;/code&gt; custom property invalidates 2,400 style nodes, unstable context values trigger 14 synchronous VDOM reconciliations, &lt;code&gt;useLayoutEffect&lt;/code&gt; interleaves reads and writes into 14 forced layouts, the combined work creates a 180 ms Long Task, and synchronous lane scheduling blocks the browser from painting the clicked chip.&lt;/p&gt;

&lt;h2&gt;
  
  
  Failure Simulator
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://frontend.rocks/autopsies/fourteen-rerenders-one-click/#failure-simulator" rel="noopener noreferrer"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fgr6sbd2x6lih41b9t960.png" alt="Interactive Failure Simulator — Click to step through the live model" width="800" height="527"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Layer Dissection
&lt;/h2&gt;

&lt;h3&gt;
  
  
  01 → 02: Root CSS Variable Mutation Triggers Cascade and Re-Render Storm
&lt;/h3&gt;

&lt;p&gt;Mutating &lt;code&gt;--row-density&lt;/code&gt; on &lt;code&gt;document.documentElement&lt;/code&gt; (&lt;code&gt;:root&lt;/code&gt;) forces Blink to re-evaluate inherited &lt;a href="https://frontend.rocks/concepts/css-custom-properties-cascade" rel="noopener noreferrer"&gt;CSS Custom Properties &amp;amp; Cascade&lt;/a&gt; across all 2,400 descendant nodes.&lt;/p&gt;

&lt;p&gt;Simultaneously, the click handler updates a top-level provider whose &lt;code&gt;value={{ filter, density }}&lt;/code&gt; literal allocates a fresh object reference. Under &lt;a href="https://frontend.rocks/concepts/virtual-dom-reconciliation" rel="noopener noreferrer"&gt;Virtual DOM &amp;amp; Reconciliation&lt;/a&gt;, every consumer subtree fails &lt;code&gt;Object.is&lt;/code&gt; equality and schedules 14 cascading re-renders.&lt;/p&gt;

&lt;h3&gt;
  
  
  02 → 03: Commit Effects Interleave Reads and Writes Into Layout Thrashing
&lt;/h3&gt;

&lt;p&gt;During the synchronous commit phase of those 14 re-renders, &lt;code&gt;useLayoutEffect&lt;/code&gt; loops over visible rows to equalize heights:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Read&lt;/strong&gt;: &lt;code&gt;el.getBoundingClientRect().height&lt;/code&gt; forces Blink to flush pending &lt;code&gt;:root&lt;/code&gt; style invalidations and compute geometry immediately.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Write&lt;/strong&gt;: &lt;code&gt;el.style.minHeight = ...&lt;/code&gt; marks the box tree dirty again for the next iteration.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Repeating this read-write pair 14 times triggers &lt;a href="https://frontend.rocks/concepts/layout-thrashing" rel="noopener noreferrer"&gt;Layout Thrashing (Forced Synchronous Layout)&lt;/a&gt; and shifts the sticky header before paint.&lt;/p&gt;

&lt;h3&gt;
  
  
  03 → 04: Forced Layouts Inflate the Interaction Into a 180 ms Long Task
&lt;/h3&gt;

&lt;p&gt;Because &lt;code&gt;useLayoutEffect&lt;/code&gt; executes synchronously before Blink composites the next frame, 2,400 style recalculations, 14 VDOM diffs, and 14 forced layouts execute inside one macrotask. Under &lt;a href="https://frontend.rocks/concepts/long-tasks-and-inp" rel="noopener noreferrer"&gt;Long Tasks and Interaction to Next Paint (INP)&lt;/a&gt;, any task exceeding 50 ms starves the renderer; at 180 ms, the active chip remains unpressed for 11 frames.&lt;/p&gt;

&lt;h3&gt;
  
  
  04 → 05: SyncLane Prevents Yielding Between Urgent Chip Paint and Grid Work
&lt;/h3&gt;

&lt;p&gt;Calling &lt;code&gt;setFilter(next)&lt;/code&gt; directly schedules the 500-row grid filter on React's &lt;a href="https://frontend.rocks/concepts/concurrent-rendering-lanes" rel="noopener noreferrer"&gt;Priority Lanes &amp;amp; Time-Slicing Schedulers&lt;/a&gt; (&lt;code&gt;SyncLane&lt;/code&gt;).&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Synchronous lane&lt;/strong&gt;: Blocks Blink from painting the pressed chip until all 500 rows reconcile.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Transition lane&lt;/strong&gt;: Wrapping &lt;code&gt;setFilter(next)&lt;/code&gt; in &lt;code&gt;startTransition&lt;/code&gt; yields between chunks so the chip paints in under 16 ms.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Architectural Fix &amp;amp; Invariants
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nc"&gt;FilterBar&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;gridRef&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;rowsRef&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;setUrgentChip&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;setGridFilter&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Props&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;handleSelect&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;next&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;FilterState&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;setUrgentChip&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;next&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// SyncLane: paints pressed chip in &amp;lt; 16 ms&lt;/span&gt;
    &lt;span class="n"&gt;gridRef&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;current&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;style&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setProperty&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'--row-density'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;next&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;density&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="nf"&gt;startTransition&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nf"&gt;setGridFilter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;next&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// TransitionLane: yieldable 500-row reconciliation&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="nf"&gt;requestAnimationFrame&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;heights&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;rowsRef&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;current&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;el&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;el&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getBoundingClientRect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;height&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="n"&gt;rowsRef&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;current&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;el&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;el&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;style&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;minHeight&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sb"&gt;`${heights[i] + 4}px`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;ChipGroup&lt;/span&gt; &lt;span class="n"&gt;onSelect&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;handleSelect&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Architectural Invariants:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Scoped custom properties&lt;/strong&gt;: Write dynamic CSS variables to the nearest container (&lt;code&gt;gridRef.current&lt;/code&gt;) with &lt;code&gt;contain: layout style&lt;/code&gt;, never &lt;code&gt;:root&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Two-lane input split&lt;/strong&gt;: Keep immediate visual feedback (&lt;code&gt;setUrgentChip&lt;/code&gt;) on &lt;code&gt;SyncLane&lt;/code&gt; and wrap expensive list filtering in &lt;code&gt;startTransition&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Strict read-then-write batching&lt;/strong&gt;: Complete all &lt;code&gt;getBoundingClientRect()&lt;/code&gt; reads in one pass before executing any &lt;code&gt;style&lt;/code&gt; mutations.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;INP budget gate&lt;/strong&gt;: Fail performance CI on any interaction trace whose total &lt;code&gt;Presentation Delay&lt;/code&gt; exceeds 100 ms or triggers more than 1 &lt;code&gt;Layout&lt;/code&gt; event per frame.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Golden Rule:&lt;/strong&gt; Keep urgent feedback on &lt;code&gt;SyncLane&lt;/code&gt;, push heavy list reconciliation to &lt;code&gt;TransitionLane&lt;/code&gt;, and never interleave DOM geometry reads with style writes.&lt;/p&gt;

</description>
      <category>frontend</category>
      <category>webdev</category>
      <category>browsers</category>
      <category>architecture</category>
    </item>
    <item>
      <title>Autopsy #02: Anatomy of a Memory Leak on an 8-Hour Dashboard</title>
      <dc:creator>frontend.rocks</dc:creator>
      <pubDate>Tue, 17 Nov 2026 16:29:59 +0000</pubDate>
      <link>https://dev.to/frontend_rocks/autopsy-02-anatomy-of-a-memory-leak-on-an-8-hour-dashboard-2m32</link>
      <guid>https://dev.to/frontend_rocks/autopsy-02-anatomy-of-a-memory-leak-on-an-8-hour-dashboard-2m32</guid>
      <description>&lt;h2&gt;
  
  
  Incident Report
&lt;/h2&gt;

&lt;p&gt;A routine PR added an auto-resizing &lt;code&gt;MutationObserver&lt;/code&gt; to the NOC telemetry table widget so column widths adjusted when live alerts streamed in. Every 10-minute QA smoke test passed with flat memory graphs.&lt;/p&gt;

&lt;p&gt;Six hours into the Monday shift, dedicated wallboard monitors running the dispatch SPA began crashing with Chrome's &lt;code&gt;Aw, Snap!&lt;/code&gt; (&lt;code&gt;Out of Memory&lt;/code&gt;) error.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;T+00:00&lt;/strong&gt;: Initial JS heap settles at 120 MB after dashboard boot.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;T+02:00&lt;/strong&gt;: Operators switch between regional tabs; heap climbs at 280 MB/hour to 680 MB.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;T+05:30&lt;/strong&gt;: V8 Mark-Compact GC pauses hit 900 ms per frame; DevTools heap snapshots show 18,400 &lt;code&gt;Detached HTMLDivElement&lt;/code&gt; nodes and 28 retained &lt;code&gt;FiberNode&lt;/code&gt; trees.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;T+07:45&lt;/strong&gt;: Renderer process crosses 2.4 GB and terminates with &lt;code&gt;Aw, Snap!&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The Red Herring
&lt;/h2&gt;

&lt;p&gt;The first Slack reflex was to add &lt;code&gt;telemetryRows = null&lt;/code&gt; and &lt;code&gt;host = null&lt;/code&gt; inside the &lt;code&gt;useEffect&lt;/code&gt; cleanup function. Local testing showed a brief drop in the DevTools memory timeline after manual GC, so the team shipped the hotfix.&lt;/p&gt;

&lt;p&gt;Production crashes continued on the exact same 6-to-8-hour cadence. Nulling local bindings inside a cleanup closure does not sever the native C++ retainer edge held by an active &lt;code&gt;MutationObserver&lt;/code&gt; or an uncancelled &lt;code&gt;fetch&lt;/code&gt; stream.&lt;/p&gt;

&lt;h2&gt;
  
  
  Causal Chain
&lt;/h2&gt;

&lt;p&gt;The leak compounds across five runtime layers. Uncollected allocations promote into V8 Old Space, native DOM observers act as immortal GC roots, stale hook closures pull entire component trees into those roots, un-disconnected &lt;code&gt;MutationObserver&lt;/code&gt; instances persist across route unmounts, and absent &lt;code&gt;AbortController&lt;/code&gt; wiring leaves no unified teardown path.&lt;/p&gt;

&lt;h2&gt;
  
  
  Failure Simulator
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://frontend.rocks/autopsies/eight-hour-spa-memory-leak/#failure-simulator" rel="noopener noreferrer"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fgttxtvxpp0gcho2gsctm.png" alt="Interactive Failure Simulator — Click to step through the live model" width="800" height="527"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Layer Dissection
&lt;/h2&gt;

&lt;h3&gt;
  
  
  01 → 02: Surviving Allocations Promote to Immortal Retainers
&lt;/h3&gt;

&lt;p&gt;Under &lt;a href="https://frontend.rocks/concepts/js-garbage-collection" rel="noopener noreferrer"&gt;JavaScript Generational Garbage Collection&lt;/a&gt;, short-lived objects die in V8's Young Generation during fast Scavenge cycles. Allocations that remain reachable across two scavenges promote into Old Space, where reclamation requires expensive Mark-Compact sweeps.&lt;/p&gt;

&lt;p&gt;As shown in &lt;a href="https://frontend.rocks/concepts/js-memory-leaks-retainers" rel="noopener noreferrer"&gt;Memory Leaks, Retainers, and Detached DOM Trees&lt;/a&gt;, a single reachable JS reference to an unmounted &lt;code&gt;&amp;lt;div class="chart-host"&amp;gt;&lt;/code&gt; pins the entire detached DOM subtree in Old Space.&lt;/p&gt;

&lt;h3&gt;
  
  
  02 → 03: Retainer Paths Originate in Stale Hook Closures
&lt;/h3&gt;

&lt;p&gt;The retainer edge rarely comes from a global &lt;code&gt;window.leak = node&lt;/code&gt; assignment. Instead, &lt;a href="https://frontend.rocks/concepts/stale-closures-hooks" rel="noopener noreferrer"&gt;Stale Closures in Hooks &amp;amp; Callbacks&lt;/a&gt; capture the lexical environment of the render in which an effect was created:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Captured state&lt;/strong&gt;: A 40 MB &lt;code&gt;telemetryRows&lt;/code&gt; array from &lt;code&gt;t = 0h 15m&lt;/code&gt; stays bound inside the callback scope.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Captured ref&lt;/strong&gt;: &lt;code&gt;widgetRef.current&lt;/code&gt; points to the detached DOM container after the user navigates to another route.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  03 → 04: Native MutationObserver Keeps the Closure Reachable
&lt;/h3&gt;

&lt;p&gt;V8 fails to collect the stale closure after unmount because &lt;a href="https://frontend.rocks/concepts/mutation-observer" rel="noopener noreferrer"&gt;MutationObserver and Batched Microtask Delivery&lt;/a&gt; registers the callback inside Blink's C++ DOM mutation agent.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Native GC root&lt;/strong&gt;: Until &lt;code&gt;observer.disconnect()&lt;/code&gt; runs, Blink holds a strong edge to the JS callback.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Retained graph&lt;/strong&gt;: Every variable and DOM node inside that callback closure remains reachable across route swaps.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  04 → 05: Absent AbortController Prevents Unified Teardown
&lt;/h3&gt;

&lt;p&gt;In the incident codebase, the effect also opened a &lt;code&gt;fetch&lt;/code&gt; stream and attached a &lt;code&gt;window&lt;/code&gt; &lt;code&gt;resize&lt;/code&gt; listener. Without &lt;a href="https://frontend.rocks/concepts/abortcontroller-cancellation" rel="noopener noreferrer"&gt;AbortController and Cooperative Cancellation&lt;/a&gt;, early returns skipped &lt;code&gt;observer.disconnect()&lt;/code&gt; whenever &lt;code&gt;host&lt;/code&gt; changed mid-flight, leaving partial subscriptions alive.&lt;/p&gt;

&lt;h2&gt;
  
  
  Architectural Fix &amp;amp; Invariants
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="nf"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;host&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;widgetRef&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;current&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;host&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;controller&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;AbortController&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;signal&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;controller&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;observer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;MutationObserver&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;syncLayout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;host&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;observer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;observe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;host&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;childList&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;subtree&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;signal&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'abort'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;observer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;disconnect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;once&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'resize'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;syncLayout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;host&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;signal&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nb"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'/api/telemetry'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;signal&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;rows&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;renderChart&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;host&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;rows&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;err&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="s1"&gt;'AbortError'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nf"&gt;reportError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;controller&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;abort&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Architectural Invariants:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Single-token teardown&lt;/strong&gt;: Every &lt;code&gt;useEffect&lt;/code&gt; that allocates a DOM observer, &lt;code&gt;window&lt;/code&gt; listener, or network stream creates one &lt;code&gt;AbortController&lt;/code&gt; and returns &lt;code&gt;() =&amp;gt; controller.abort()&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Paired observer disconnect&lt;/strong&gt;: Every &lt;code&gt;observer.observe()&lt;/code&gt; call registers &lt;code&gt;{ once: true }&lt;/code&gt; on &lt;code&gt;signal&lt;/code&gt; to invoke &lt;code&gt;observer.disconnect()&lt;/code&gt; atomically.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Thin callback scopes&lt;/strong&gt;: Observers read only the DOM node passed to their callback or a mutable &lt;code&gt;ref&lt;/code&gt;, never large historical state arrays from outer renders.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Soak-test verification&lt;/strong&gt;: Navigation stress tests swap routes 50 times in Playwright and assert &lt;code&gt;Detached&lt;/code&gt; node count returns to baseline after &lt;code&gt;gc()&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Golden Rule:&lt;/strong&gt; Nulling variables never collects memory held by native C++ DOM roots; bind every observer, listener, and fetch to one &lt;code&gt;AbortSignal&lt;/code&gt; and abort on unmount.&lt;/p&gt;

</description>
      <category>frontend</category>
      <category>webdev</category>
      <category>browsers</category>
      <category>architecture</category>
    </item>
    <item>
      <title>Autopsy #01: Anatomy of a Double Payment in Production</title>
      <dc:creator>frontend.rocks</dc:creator>
      <pubDate>Tue, 17 Nov 2026 16:07:45 +0000</pubDate>
      <link>https://dev.to/frontend_rocks/autopsy-01-anatomy-of-a-double-payment-in-production-2l8h</link>
      <guid>https://dev.to/frontend_rocks/autopsy-01-anatomy-of-a-double-payment-in-production-2l8h</guid>
      <description>&lt;h2&gt;
  
  
  Incident Report
&lt;/h2&gt;

&lt;p&gt;On Friday at 14:10 UTC, a two-line PR replaced a native &lt;code&gt;&amp;lt;form&amp;gt;&lt;/code&gt; submit with a custom &lt;code&gt;onClick&lt;/code&gt; handler on the checkout button to support Apple Pay telemetry. QA verified the happy path on desktop Chrome over office fiber and approved the release.&lt;/p&gt;

&lt;p&gt;Within 40 minutes of the deploy, finance alerts flagged duplicate settlements on mobile Safari and throttled Android devices.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;T+00:00&lt;/strong&gt;: Deploy &lt;code&gt;checkout-web@4.18.2&lt;/code&gt; reaches 100% of edge PoPs.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;T+08:00&lt;/strong&gt;: Support receives the first ticket reporting two \$99.00 charges for a single &lt;code&gt;cart_id&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;T+19:00&lt;/strong&gt;: Payment gateway logs show 0.42% of &lt;code&gt;POST /v1/charges&lt;/code&gt; requests arriving in pairs spaced 80 ms to 3,400 ms apart, both returning &lt;code&gt;200 OK&lt;/code&gt; with distinct &lt;code&gt;charge_id&lt;/code&gt; values.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;T+42:00&lt;/strong&gt;: Refund webhooks lag 48 hours behind support volume; checkout traffic is rolled back to &lt;code&gt;4.18.1&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The Red Herring
&lt;/h2&gt;

&lt;p&gt;The on-call engineer's first Slack reflex was to add &lt;code&gt;disabled={isSubmitting}&lt;/code&gt; on the &lt;code&gt;&amp;lt;button&amp;gt;&lt;/code&gt; element and guard the handler with &lt;code&gt;if (isSubmitting) return;&lt;/code&gt;. The patch passed every local Playwright test on localhost with zero duplicate requests.&lt;/p&gt;

&lt;p&gt;In production, the patch failed to reduce the 0.42% duplicate rate for two reasons:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Async render lag&lt;/strong&gt;: &lt;code&gt;setIsSubmitting(true)&lt;/code&gt; schedules a React render for the next frame; &lt;code&gt;button.disabled&lt;/code&gt; stays &lt;code&gt;false&lt;/code&gt; when a second &lt;code&gt;click&lt;/code&gt; enters the call stack 12 ms later.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Premature timeout reset&lt;/strong&gt;: A 3-second client timeout in &lt;code&gt;catch&lt;/code&gt; reset &lt;code&gt;isSubmitting&lt;/code&gt; to &lt;code&gt;false&lt;/code&gt; on slow 3G connections while the first &lt;code&gt;POST&lt;/code&gt; socket remained open in flight.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Causal Chain
&lt;/h2&gt;

&lt;p&gt;The duplicate charge requires five consecutive layer failures. A synchronous DOM event outruns asynchronous React state, uncoalesced callbacks fire two network requests, boolean flags allow re-entry after a timeout, uncancelled sockets finish in the background, and a stateless server commits both payloads.&lt;/p&gt;

&lt;h2&gt;
  
  
  Failure Simulator
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://frontend.rocks/autopsies/double-payment-race-condition/#failure-simulator" rel="noopener noreferrer"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fxote12odltula1jew2wg.png" alt="Interactive Failure Simulator — Click to step through the live model" width="800" height="527"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Layer Dissection
&lt;/h2&gt;

&lt;h3&gt;
  
  
  01 → 02: Synchronous DOM Dispatch Outruns Async React Commit
&lt;/h3&gt;

&lt;p&gt;In &lt;a href="https://frontend.rocks/concepts/dom-event-propagation" rel="noopener noreferrer"&gt;DOM Event Propagation (Capture, Target, Bubble)&lt;/a&gt;, Blink dispatches &lt;code&gt;click&lt;/code&gt; events synchronously from the native input queue into the JavaScript call stack. When &lt;code&gt;onClick&lt;/code&gt; invokes &lt;code&gt;setIsSubmitting(true)&lt;/code&gt;, React enqueues a state update for the next render pass while &lt;code&gt;button.disabled&lt;/code&gt; remains &lt;code&gt;false&lt;/code&gt; during the current frame.&lt;/p&gt;

&lt;p&gt;A second tap arriving 12 ms later hits the same active DOM node. Because &lt;a href="https://frontend.rocks/concepts/debounce-throttle-raf-coalescing" rel="noopener noreferrer"&gt;Debounce, Throttle &amp;amp; rAF Coalescing&lt;/a&gt; is absent on the leading edge, both closures read &lt;code&gt;isSubmitting === false&lt;/code&gt; and enter &lt;code&gt;submitPayment()&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  02 → 03: Uncoalesced Handlers Feed Re-Entrant Boolean State
&lt;/h3&gt;

&lt;p&gt;Even when a leading-edge lock blocks sub-second double-clicks, cellular handoffs introduce a 3.2-second TLS or gateway stall. Under &lt;a href="https://frontend.rocks/concepts/finite-state-machines-ui" rel="noopener noreferrer"&gt;Finite State Machines for UI&lt;/a&gt;, a &lt;code&gt;SUBMITTING&lt;/code&gt; state cannot transition back to &lt;code&gt;IDLE&lt;/code&gt; on a client-side timer while the HTTP socket remains open.&lt;/p&gt;

&lt;p&gt;Boolean flags (&lt;code&gt;isSubmitting&lt;/code&gt;, &lt;code&gt;hasTimedOut&lt;/code&gt;) violate that invariant. A &lt;code&gt;catch&lt;/code&gt; block executes &lt;code&gt;setIsSubmitting(false)&lt;/code&gt; at &lt;code&gt;t = 3,000 ms&lt;/code&gt;, re-enabling the button while Request #1 is still traversing the carrier network.&lt;/p&gt;

&lt;h3&gt;
  
  
  03 → 04: Re-Enabled UI Leaves Orphaned Sockets on the Wire
&lt;/h3&gt;

&lt;p&gt;When the user taps "Pay" a second time, Request #2 enters the network stack alongside Request #1. Without &lt;a href="https://frontend.rocks/concepts/abortcontroller-cancellation" rel="noopener noreferrer"&gt;AbortController and Cooperative Cancellation&lt;/a&gt;, the client never signals intent to drop Request #1, and an aborted &lt;code&gt;fetch()&lt;/code&gt; only closes the local socket after the server may have parsed the TCP payload.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Client view&lt;/strong&gt;: Marks Request #1 failed at &lt;code&gt;t = 3,000 ms&lt;/code&gt; and dispatches Request #2.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Server view&lt;/strong&gt;: Receives Request #1 at &lt;code&gt;t = 3,150 ms&lt;/code&gt; and Request #2 at &lt;code&gt;t = 3,420 ms&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  04 → 05: Stateless Retries Commit Twice Without Idempotency Keys
&lt;/h3&gt;

&lt;p&gt;Both HTTP requests reach the payment endpoint as independent mutations. As documented in &lt;a href="https://frontend.rocks/concepts/idempotency-optimistic-queues" rel="noopener noreferrer"&gt;Outbox Queues, Idempotency Keys &amp;amp; Causal Ordering&lt;/a&gt;, HTTP &lt;code&gt;POST&lt;/code&gt; is non-idempotent by specification; only an explicit &lt;code&gt;Idempotency-Key&lt;/code&gt; header scoped to the checkout intent lets the gateway deduplicate Request #2 and replay Request #1's receipt.&lt;/p&gt;

&lt;h2&gt;
  
  
  Architectural Fix &amp;amp; Invariants
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nc"&gt;PayState&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'idle'&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="s1"&gt;'submitting'&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="s1"&gt;'settled'&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="s1"&gt;'failed'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;createPaymentSubmitter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;intentUuid&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;PayState&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'idle'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;controller&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;AbortController&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;submit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;unknown&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Response&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;state&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="s1"&gt;'submitting'&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="n"&gt;state&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="s1"&gt;'settled'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;state&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'submitting'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nb"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'/v1/charges'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;method&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'POST'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s1"&gt;'Content-Type'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'application/json'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'Idempotency-Key'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;intentUuid&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;signal&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;controller&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;signal&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="n"&gt;state&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ok&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="s1"&gt;'settled'&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'failed'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;state&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'failed'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Architectural Invariants:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Synchronous transition guard&lt;/strong&gt;: Mutate &lt;code&gt;idle → submitting&lt;/code&gt; synchronously before any &lt;code&gt;await&lt;/code&gt; or React render commit to block same-frame double-clicks.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Stable intent key&lt;/strong&gt;: Generate &lt;code&gt;intentUuid&lt;/code&gt; once per checkout form mount and reuse it across all retries so the gateway deduplicates re-submissions.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Terminal settled state&lt;/strong&gt;: Treat &lt;code&gt;settled&lt;/code&gt; as final for a given &lt;code&gt;intentUuid&lt;/code&gt;; starting another payment requires a fresh mount and UUID.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cooperative teardown&lt;/strong&gt;: Call &lt;code&gt;controller.abort()&lt;/code&gt; on unmount so stale responses never mutate unmounted UI state.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Golden Rule:&lt;/strong&gt; Never guard a financial mutation with React's asynchronous render state; lock synchronously in memory and deduplicate idempotently on the server.&lt;/p&gt;

</description>
      <category>frontend</category>
      <category>webdev</category>
      <category>browsers</category>
      <category>architecture</category>
    </item>
    <item>
      <title>Autopsy #13: The useEffect Dependency Loop That DDoSed Our Own API</title>
      <dc:creator>frontend.rocks</dc:creator>
      <pubDate>Tue, 17 Nov 2026 10:56:33 +0000</pubDate>
      <link>https://dev.to/frontend_rocks/autopsy-13-the-useeffect-dependency-loop-that-ddosed-our-own-api-4a8l</link>
      <guid>https://dev.to/frontend_rocks/autopsy-13-the-useeffect-dependency-loop-that-ddosed-our-own-api-4a8l</guid>
      <description>&lt;h2&gt;
  
  
  Incident Report
&lt;/h2&gt;

&lt;p&gt;A filter bar refactor wrapped &lt;code&gt;searchParams.get('status')&lt;/code&gt; inside an object literal (&lt;code&gt;const filter = { status }&lt;/code&gt;) to match a shared hook signature. In local dev, the page rendered and updated the URL bar without visible errors.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;T+00:00&lt;/strong&gt;: Deployed the filter bar refactor to production.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;T+03:00&lt;/strong&gt;: API gateway telemetry recorded a 48x spike in &lt;code&gt;GET /api/items&lt;/code&gt; traffic and a 64% rate of &lt;code&gt;429 Too Many Requests&lt;/code&gt; responses.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;T+05:00&lt;/strong&gt;: Client error tracking logged &lt;code&gt;Maximum update depth exceeded&lt;/code&gt; across 19% of active dashboard sessions.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;T+06:30&lt;/strong&gt;: Network waterfalls showed a single filter click spawning 47 uncancelled &lt;code&gt;GET /api/items?status=open&lt;/code&gt; requests within 420 ms while main-thread CPU hit 99%.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The Red Herring
&lt;/h2&gt;

&lt;p&gt;In &lt;code&gt;#inc-frontend&lt;/code&gt;, the team added a 300 ms &lt;code&gt;debounce&lt;/code&gt; around the &lt;code&gt;fetch()&lt;/code&gt; call inside &lt;code&gt;useEffect&lt;/code&gt;. In local dev, the network tab appeared calmer for the first quarter-second.&lt;/p&gt;

&lt;p&gt;In production, debouncing only delayed the first burst by 300 ms. The component continued re-rendering in a tight loop because the underlying dependency reference changed on every execution frame, starving the main thread and still tripping the 30 req/s gateway rate limiter.&lt;/p&gt;

&lt;h2&gt;
  
  
  Causal Chain
&lt;/h2&gt;

&lt;p&gt;Five runtime layers amplify a single URL filter change into an API self-DDoS. Per-render heap allocation, bidirectional closure drift, &lt;code&gt;Object.is()&lt;/code&gt; reference inequality, absent cache key deduplication, and uncancelled &lt;code&gt;fetch()&lt;/code&gt; streams compound into rate-limit exhaustion.&lt;/p&gt;

&lt;h2&gt;
  
  
  Failure Simulator
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://frontend.rocks/autopsies/useeffect-dependency-loop-ddos/#failure-simulator" rel="noopener noreferrer"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F93vvbzrfmykgasvfkr7s.png" alt="Interactive Failure Simulator — Click to step through the live model" width="800" height="552"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Layer Dissection
&lt;/h2&gt;

&lt;h3&gt;
  
  
  01 → 02: Fresh Heap Allocations Break Closure Stability
&lt;/h3&gt;

&lt;p&gt;During each render, the component constructs &lt;code&gt;const filter = { status: searchParams.get('status') ?? 'open' }&lt;/code&gt; directly in the function body. Under &lt;a href="https://frontend.rocks/concepts/execution-context-call-stack" rel="noopener noreferrer"&gt;Execution Context, Call Stack &amp;amp; Closures&lt;/a&gt;, every invocation creates a new execution context and allocates a distinct object address on the V8 heap.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;filter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'status'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;??&lt;/span&gt; &lt;span class="s1"&gt;'open'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// new heap address per call&lt;/span&gt;
&lt;span class="nf"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;setMirrorFilter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// schedules re-render #2 with stale searchParams closure&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;setSearchParams&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Simultaneously, a second &lt;code&gt;useEffect&lt;/code&gt; copies &lt;code&gt;mirrorFilter&lt;/code&gt; back into &lt;code&gt;URLSearchParams&lt;/code&gt;. Because hooks read values from their own render snapshot under &lt;a href="https://frontend.rocks/concepts/stale-closures-hooks" rel="noopener noreferrer"&gt;Stale Closures &amp;amp; Hook Traps&lt;/a&gt;, two concurrent updates bounce outdated filter values between local state and the URL bar.&lt;/p&gt;

&lt;h3&gt;
  
  
  02 → 03: Reference Inequality Reschedules the Effect Loop
&lt;/h3&gt;

&lt;p&gt;Before committing an effect, React compares each entry in the dependency array against the previous render's array using &lt;code&gt;Object.is()&lt;/code&gt;. Under &lt;a href="https://frontend.rocks/concepts/virtual-dom-reconciliation" rel="noopener noreferrer"&gt;Virtual DOM &amp;amp; Reconciliation&lt;/a&gt;, two object literals with identical properties fail reference equality:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Primitive string &lt;code&gt;'open'&lt;/code&gt;&lt;/strong&gt;: &lt;code&gt;Object.is('open', 'open')&lt;/code&gt; returns &lt;code&gt;true&lt;/code&gt; and skips effect execution.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Object literal &lt;code&gt;{ status: 'open' }&lt;/code&gt;&lt;/strong&gt;: &lt;code&gt;Object.is(@0x7f1a04, @0x7f1b88)&lt;/code&gt; returns &lt;code&gt;false&lt;/code&gt; and schedules another commit.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Because the effect calls &lt;code&gt;setMirrorFilter(filter)&lt;/code&gt; inside its body, every failed &lt;code&gt;Object.is()&lt;/code&gt; check triggers a synchronous state update, allocating &lt;code&gt;@0x7f1b88&lt;/code&gt; on the next render until React hits its 50-update depth guard.&lt;/p&gt;

&lt;h3&gt;
  
  
  03 → 04: Absent Cache Key Deduplication Multiplies Network Traffic
&lt;/h3&gt;

&lt;p&gt;Every iteration of the render loop invokes &lt;code&gt;fetch('/api/items?status=' + filter.status)&lt;/code&gt; directly inside &lt;code&gt;useEffect&lt;/code&gt;. Without &lt;a href="https://frontend.rocks/concepts/server-state-cache-machines" rel="noopener noreferrer"&gt;Server-State Cache Machines&lt;/a&gt;, the client maintains no finite state machine or primitive cache key (&lt;code&gt;['items', 'open']&lt;/code&gt;) to coalesce identical concurrent reads.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Cache miss per render&lt;/strong&gt;: 47 renders generate 47 independent HTTP requests for the exact same payload.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Thundering client&lt;/strong&gt;: No &lt;code&gt;staleTime&lt;/code&gt; or in-flight deduplication map blocks duplicate reads from leaving the browser.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  04 → 05: Uncancelled Sockets Saturate the Gateway Into 429
&lt;/h3&gt;

&lt;p&gt;None of the 47 &lt;code&gt;fetch()&lt;/code&gt; calls pass an &lt;code&gt;AbortSignal&lt;/code&gt; or return a cleanup function. Under &lt;a href="https://frontend.rocks/concepts/abortcontroller-cancellation" rel="noopener noreferrer"&gt;AbortController &amp;amp; Cooperative Cancellation&lt;/a&gt;, the browser keeps every initiated HTTP/2 stream open until the server responds or times out, stacking stale responses and tripping the 30 req/s per-IP token bucket into &lt;code&gt;429 Too Many Requests&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Architectural Fix &amp;amp; Invariants
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nc"&gt;ItemsView&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useSearchParams&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;status&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'status'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;??&lt;/span&gt; &lt;span class="s1"&gt;'open'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;items&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;setItems&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;useState&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Item&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="nf"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;controller&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;AbortController&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nb"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sb"&gt;`/api/items?status=${encodeURIComponent(status)}`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;signal&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;controller&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;signal&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ok&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;reject&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;setItems&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;err&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="s1"&gt;'AbortError'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;controller&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;abort&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Architectural Invariants&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Single source of truth&lt;/strong&gt;: URL query parameters own filter state; mirror &lt;code&gt;useState&lt;/code&gt; copies of URL values are prohibited.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Primitive dependency keys&lt;/strong&gt;: &lt;code&gt;useEffect&lt;/code&gt; and server-state cache keys accept only primitive strings, numbers, or booleans, never inline object literals.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Mandatory cooperative cancellation&lt;/strong&gt;: Every effect-driven &lt;code&gt;fetch()&lt;/code&gt; passes an &lt;code&gt;AbortController.signal&lt;/code&gt; and aborts in its cleanup function.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Gateway rate-limit budget&lt;/strong&gt;: Integration tests fail if a single filter change dispatches more than 1 network request or leaves uncancelled requests on unmount.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Golden Rule:&lt;/strong&gt; Never pass freshly allocated objects into &lt;code&gt;useEffect&lt;/code&gt; dependencies or mirror URL state in &lt;code&gt;useState&lt;/code&gt;; depend on primitives, deduplicate reads by key, and abort every in-flight fetch on cleanup.&lt;/p&gt;

</description>
      <category>frontend</category>
      <category>webdev</category>
      <category>browsers</category>
      <category>architecture</category>
    </item>
  </channel>
</rss>
