Skip to content
  • Home
  • About
  • No Access
  • Privacy Policy
Bits of .NET
Bits of .NET
  • C#
  • Asp.Net Core
  • SQL
  • Windows
  • WordPress
  • AI
  • JavaScript
  • CSS
  • MORE
    • HTML
    • Ajax
    • Git
    • Docker
    • Kubernetes
    • Photoshop
    • Visual Studio

Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

  • C#
  • Asp.Net Core
  • SQL
  • Windows
  • WordPress
  • AI
  • JavaScript
  • CSS
  • MORE
    • HTML
    • Ajax
    • Git
    • Docker
    • Kubernetes
    • Photoshop
    • Visual Studio
JavaScript

JavaScript: Fix a Proxy Trap Missing Updates From a Nested Object

- 25.11.26 - ErcanOPAK

⚡ JavaScript: Fix a Proxy Trap Missing Updates From a Nested Object

A Proxy only intercepts property access on the exact object it wraps — when a property’s value is itself a nested object, reading it through the proxy returns the raw inner object, not a further proxy-wrapped version, so a mutation made directly on that nested object never triggers the outer proxy’s set trap at all, which quietly breaks any reactive system that assumes every write anywhere in the tree gets observed.

🔎 The Problem

const state = new Proxy({ user: { name: 'Ana' } }, {
  set(target, key, value) {
    console.log('changed:', key);
    target[key] = value;
    return true;
  }
});

state.count = 1;          // logs 'changed: count' - works
state.user.name = 'Ben';  // logs nothing at all - trap never fires,
                          // state.user is the raw object, not a Proxy

✅ Fix: Wrap Nested Objects in Their Own Proxy, Lazily

  • Wrap nested object values in their own proxy inside the get trap, returning a new proxy over any object-typed property the first time it’s read, so writes anywhere in the tree route back through a trap instead of only at the top level.
  • Keep a WeakMap from raw object to its already-created proxy so the same nested object doesn’t get wrapped twice, which would otherwise make equality checks behave inconsistently between reads.
  • Test specifically by mutating a deeply nested property and confirming the trap actually fires — a reactive UI that “mostly updates” is usually missing exactly this, with nested writes silently unobserved.

🚨 Why This Is Dangerous

  • A state manager built on Proxy reactivity that misses nested mutations doesn’t throw an error — it just stops re-rendering for that one branch of state, which looks like a vague “sometimes stale” bug that’s hard to reproduce reliably.

A Proxy only ever watches the object you handed it — everything one property deeper is somebody else’s object until you wrap that one too.

— JavaScript Tip

Related posts:

JavaScript: Building a Task Management App with Array Methods

JavaScript: Building a Task Management App with Array Methods

JavaScript: Use Destructuring to Extract Values Elegantly

JavaScript: Use Destructuring to Extract Values Elegantly

JavaScript: Use ?? Instead of || for Default Values

JavaScript: Use ?? Instead of || for Default Values

Views: 7
Found this useful? Share it
XLinkedInWhatsApp

Post navigation

The AI Prompt That Turns a Moving Quote Into a Red-Flag Checklist
C#: Fix a Ref Readonly Parameter Silently Copying on Call

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Most Read

  1. 01How to make theater mode the default for Youtube 1,079 views
  2. 02How to add default value for Entity Framework migrations for DateTime and Bool 997 views
  3. 03Get the User Name and Domain Name from an Email Address in SQL 996 views
  4. 04Get the First and Last Word from a String or Sentence in SQL 873 views
  5. 05How to select distinct rows in a datatable in C# 868 views
  6. 06How to enable, disable and check if Service Broker is enabled on a database in SQL Server 671 views
  7. 07Add Constraint to SQL Table to ensure email contains @ 631 views
  8. 08Average of all values in a column that are not zero in SQL 584 views
  9. 09How to use Map Mode for Vertical Scroll Mode in Visual Studio 562 views
Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

Social

  • ErcanOPAK.com
  • GoodReads
  • LetterBoxD
  • Linkedin
  • The Blog
  • Twitter
Back to top
© 2026 Bits of .NET | Built with Xblog Plus free WordPress theme by wpthemespace.com