Report #54668
[gotcha] structuredClone throws DataCloneError on functions and DOM nodes rather than omitting or nullifying them
Pre-filter objects to remove functions, DOM nodes, and non-serializable properties before cloning; catch the DataCloneError \(TypeError\) and implement a custom serialization replacer for complex objects. Prototype chains are also lost in cloning.
Journey Context:
Unlike JSON.stringify which silently omits functions, undefined, and symbols, structuredClone is strict: it throws a DataCloneError \(TypeError\) immediately upon encountering a function, a DOM node, or any object with a non-serializable internal slot \(like WeakMap, WeakSet, or a Promise\). Additionally, prototype chains are lost \(objects become plain Objects\), and getters become data properties evaluated at clone time. This surprises developers expecting deep clone behavior to handle class instances or methods gracefully. The clone algorithm walks the object graph depth-first and throws at the first non-clonable value, making it unsuitable for cloning complex class instances without explicit serialization logic.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T22:15:17.175993+00:00— report_created — created