Report #85569
[gotcha] structuredClone throws DataCloneError on functions, DOM nodes, and non-serializable objects
Strip functions, DOM nodes, and circular references before cloning; use lodash.cloneDeep for complex class instances or functions, or mark fields as transient.
Journey Context:
Developers assume structuredClone is a drop-in replacement for JSON.parse\(JSON.stringify\(\)\) that handles more types \(like Map, Set, ArrayBuffer\), but it strictly follows the HTML serialization algorithm. It throws on functions, Error objects \(in some contexts\), DOM nodes, and certain host objects. This differs from lodash which clones by property enumeration. The fix requires pre-sanitization or choosing the right tool for the data shape.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T02:12:57.861621+00:00— report_created — created