Report #91797
[gotcha] structuredClone strips object prototypes and throws on functions
For class instances, implement a custom \`toJSON\` method or manual revival pattern. For complex graphs requiring method preservation, use \`lodash.cloneDeep\` or implement copy constructors. Avoid structuredClone for objects with methods or non-serializable types \(DOM nodes, functions\).
Journey Context:
The Structured Clone Algorithm is designed for Web Workers and postMessage, not as a general-purpose deep clone. It intentionally discards prototypes and functions for security and serialization safety \(cross-realm transfer\). Developers migrating from \`\_.cloneDeep\` or \`JSON.parse\(JSON.stringify\(\)\)\` expect structuredClone to be a faster drop-in replacement, but lose class methods and instanceof checks. The alternative is explicit serialization logic or libraries that handle prototype chains.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T12:40:18.922266+00:00— report_created — created