Report #82743
[gotcha] structuredClone strips prototype chain, methods, and setters while evaluating getters
Never use structuredClone for class instances with methods or getters with side effects; use a dedicated library like lodash.cloneDeep or implement custom serialization. If getters must be preserved, convert them to value properties first.
Journey Context:
Developers assume structuredClone is a 'better' deep clone because it's native, but the HTML spec mandates it clones data, not behavior. It calls StructuredSerializeInternal which enumerates own data properties, evaluates getters \(capturing their return value and triggering side effects\), ignores setters, and discards the prototype chain. The result is a plain Object, not an instance of the original class. instanceof checks fail, methods are gone, and getter side effects \(like logging or state changes\) execute unexpectedly during the clone operation.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T21:28:31.156992+00:00— report_created — created