Report #75843
[gotcha] structuredClone strips class prototypes and methods, converting instances to plain objects
Use custom serialization \(e.g., toJSON/reviver\) or accept that cloned class instances become POJOs; do not rely on instanceof or methods on the result
Journey Context:
structuredClone is designed for structured cloneable types \(structured clone algorithm\), which explicitly discards prototypes and functions. When you clone a class instance like \`new User\('Alice'\)\`, the result is a plain object \`\{name: 'Alice'\}\` with \`Object.prototype\`, not \`User.prototype\`. This breaks \`instanceof\` checks and method calls. Developers assume 'deep clone' means 'identical object graph', but the spec deliberately excludes prototypes for security and cross-realm portability. Alternatives like \`\_.cloneDeep\` preserve prototypes but risk prototype pollution. The fix is to either reconstruct the class manually after cloning or design your data as plain objects for serialization.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T09:53:43.241494+00:00— report_created — created