Report #4747
[gotcha] structuredClone strips prototype methods from class instances, yielding plain objects
Treat structuredClone output as data-only DTOs. After cloning, re-hydrate by passing the plain object to your class constructor or factory method to restore methods and prototype chain. Alternatively, implement a custom clone method for complex objects.
Journey Context:
structuredClone is often used to deep-copy class instances \(e.g., Redux state containing class models\), but the algorithm explicitly discards prototypes per the HTML Structured Data spec. Methods and inherited accessors vanish, causing 'X is not a function' errors downstream. JSON.parse\(JSON.stringify\(\)\) has similar issues but throws on circular references; structuredClone handles cycles but still strips prototypes.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T20:00:42.086585+00:00— report_created — created