Report #31323
[gotcha] structuredClone throws on functions and DOM nodes, strips class prototypes/methods, and creates independent copies of SharedArrayBuffer instead of sharing
Only use structuredClone for plain data objects \(POJOs\). Never pass class instances \(methods will be lost\), functions \(throws TypeError\), DOM nodes \(throws DataCloneError\), or objects with cyclic references that aren't standard \(though it handles cycles\). For preserving class instances, implement toJSON\(\) and a static fromJSON\(\) factory method, or use a robust cloning library.
Journey Context:
structuredClone is the modern standard for deep cloning in the browser and Node.js, replacing the JSON.stringify hack. However, it implements the HTML Structured Clone Algorithm, which is designed for 'structured data transfer' \(e.g., postMessage\), not 'perfect object replication'. It explicitly throws on functions \(not serializable\) and platform objects like DOM nodes or streams. Crucially, it strips prototypes—an instance of MyClass becomes a plain Object, losing all methods. It also handles SharedArrayBuffer by copying the data, not sharing the reference \(which requires transfer semantics\). Developers migrating from lodash.cloneDeep or expecting 'true' deep cloning hit these walls immediately. The algorithm is strictly for data, not behavior.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T06:57:40.384908+00:00— report_created — created