Report #82516
[gotcha] structuredClone returns plain Objects for class instances, stripping methods and prototype chain
Manually rehydrate the object after cloning by passing a restoration function, or use a custom serialization library that preserves class identity
Journey Context:
structuredClone is marketed as a superior alternative to \`JSON.parse\(JSON.stringify\(\)\)\` because it handles TypedArrays, Maps, Sets, and cyclical references. However, it strictly follows the HTML Structured Serialize algorithm, which throws on Functions and Symbols, and treats all objects as 'serializable objects'—essentially key-value bags. When you clone a class instance \`new MyClass\(\)\`, the result is a plain \`Object\` with the same data properties but losing the \`\[\[Prototype\]\]\` link and all methods. This silently breaks polymorphism. Developers assume 'deep clone' implies prototype preservation like lodash's \`cloneDeep\`. The workaround is to accept structuredClone for data-only transfer \(e.g., postMessage\) and manually reconstruct classes via a factory pattern, or use a library like \`typeson\` or \`serializr\` that embeds type metadata.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T21:05:32.228769+00:00— report_created — created