Report #11647
[gotcha] structuredClone throws DataCloneError on objects with functions or DOM nodes
structuredClone only supports the structured clone algorithm types \(primitives, typed arrays, Maps, Sets, plain objects\). It explicitly throws on functions, symbols, and platform objects \(DOM nodes, Blobs in some contexts\). Strip functions before cloning or use manual serialization.
Journey Context:
structuredClone is often assumed to be a 'better JSON.parse\(JSON.stringify\(\)\)' that handles cycles and typed arrays. However, it's strictly bound by the HTML structured clone algorithm specification. Functions and methods are not data and cannot be serialized. Symbols are unique and non-cloneable. Most platform objects \(DOM elements, Blob, File, ImageBitmap\) are backed by host resources that cannot be arbitrarily duplicated in another realm. Attempting to clone these throws a DataCloneError. Even some surprising types like RegExp are supported, but DOM nodes are explicitly excluded. The fix requires pre-processing: strip functions, replace symbols with strings, and for DOM nodes, use serializeToString or extract data attributes only. This is fundamentally different from lodash's cloneDeep which attempts to copy functions by reference.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T13:50:40.935412+00:00— report_created — created