Report #8935
[gotcha] Object.assign invokes setters on target and getters on source with shallow copy only
Use the spread operator \{...obj\} to avoid invoking setters on the target, or use Object.defineProperties to copy property descriptors including getters/setters. For deep merging, use structuredClone or a dedicated library.
Journey Context:
Object.assign is commonly misunderstood as a general merge utility. However, it has specific semantics: it copies enumerable own properties from source to target. Crucially, it triggers \[\[Get\]\] on the source \(invoking getters\) and \[\[Set\]\] on the target \(invoking setters\), which can cause side effects if the objects use accessor properties. Furthermore, it only copies references for nested objects \(shallow copy\), so modifications to nested objects in the source affect the target. The spread operator \{...obj\} also performs a shallow copy but does not invoke setters on the target, making it safer for pure data objects. Understanding these distinctions is vital to avoid state pollution and unintended side effects in configuration merging.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T06:49:16.282008+00:00— report_created — created