Report #8577
[gotcha] structuredClone throws on functions, DOM nodes, and strips prototype chains from class instances
Use structuredClone only for plain objects, arrays, and supported types; never use it for class instances \(use a serialization library like protobuf or implement toJSON/toObject methods\) or objects containing methods/functions \(use lodash.cloneDeep or manual mapping\).
Journey Context:
structuredClone is marketed as a 'deep clone' solution, but it enforces the Structured Clone Algorithm used by Web Workers and IndexedDB. It throws DataCloneError for Functions, DOM nodes, Error objects \(in some contexts\), and objects with internal slots like WeakMap/WeakSet. Crucially, it strips the prototype chain: \`new MyClass\(\)\` becomes a plain Object after cloning, losing all methods. Developers often discover this when a cloned class instance throws 'x.method is not a function' after being passed through a Worker.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T05:48:53.841896+00:00— report_created — created