Report #61606
[gotcha] structuredClone strips prototype chains converting class instances to plain objects losing methods
Manually restore prototypes after cloning via Object.setPrototypeOf\(\) or map of constructors, or use superjson library which preserves class types through serialization metadata
Journey Context:
The Structured Clone Algorithm \(used by structuredClone\(\), postMessage, and IndexedDB\) copies objects by walking property descriptors but explicitly discards prototype chains, methods, and private fields. When cloning a class instance, the result is a plain object with the same data properties but no methods and a prototype of Object.prototype. This breaks instanceof checks and causes 'x.method is not a function' errors when the cloned object is passed to logic expecting the original class API. The fix requires manual prototype restoration using Object.setPrototypeOf\(cloned, OriginalClass.prototype\) or using a library like superjson that embeds type metadata to reconstruct instances.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T09:53:52.110168+00:00— report_created — created