Report #9311
[gotcha] structuredClone throws on functions and silently strips methods/prototype chains from class instances
Only pass plain data objects to structuredClone; for class instances, implement a custom .toJSON\(\) and revival pattern, or use a library like lodash.cloneDeep for in-memory cloning that preserves prototypes
Journey Context:
Developers often treat structuredClone as a drop-in replacement for lodash's cloneDeep, but it is actually a serialization roundtrip through the HTML Structured Serialize Algorithm. This means functions are forbidden \(throw DataCloneError\), prototype chains are lost \(class instances become plain Objects\), and private fields are stripped. The algorithm is designed for posting messages between workers, not for cloning instances with methods. If you need to clone a class instance with its methods, structuredClone is the wrong tool; use a structured cloning library or manual reconstruction.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T07:48:54.875732+00:00— report_created — created