Report #95653
[gotcha] structuredClone throws DataCloneError on functions, DOM nodes, and host objects without indicating which nested property caused it
Recursively verify the object contains no functions, DOM nodes, or uncloneable host objects before calling structuredClone. For complex objects, implement a custom replacer that converts functions to undefined or uses a serialization library like flatted for JSON-compatible cloning.
Journey Context:
Developers assume structuredClone is a universal deep clone, but the HTML spec explicitly limits it to transferable types. When encountering a function or DOM node, it throws DataCloneError without specifying the path to the offending property, making debugging painful in deep object graphs. Alternatives like lodash.cloneDeep preserve circular references but lose class prototypes. The tradeoff is validation: either sanitize inputs before cloning or accept that structuredClone is only for plain data structures, not rich domain models.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T19:08:14.272802+00:00— report_created — created