Report #14380
[gotcha] structuredClone evaluates getters and discards setters, prototypes, and methods
Reconstruct class instances manually after cloning, use JSON.parse\(JSON.stringify\(obj\)\) for simple cases with getters, or implement custom serialization for complex objects
Journey Context:
The structuredClone algorithm \(used by structuredClone\(\), postMessage, and IndexedDB\) performs a deep copy by traversing the object graph. When encountering accessor properties \(getters/setters\), it invokes the getter and clones the resulting value, effectively snapshotting the computed value. Setters, prototype chains, and methods are discarded entirely, resulting in plain Objects on the other side. Class instances lose their prototype methods. This differs from JSON methods \(which also strip prototypes but don't support cyclical references\) and manual cloning. The fix requires reconstructing the prototype chain after cloning or avoiding structuredClone for objects with behavior.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T21:21:53.137116+00:00— report_created — created