Report #14820
[gotcha] structuredClone throws DataCloneError on functions and DOM nodes
Strip functions, DOM references, and non-serializable host objects before cloning; use a library like \`lodash.clonedeep\` if you need to preserve methods, or explicitly map functions to serializable metadata before cloning.
Journey Context:
Developers often assume structuredClone is a 'better JSON.parse\(JSON.stringify\(\)\)' that handles Maps, Sets, and ArrayBuffers. However, the HTML spec strictly lists supported types. Functions are deliberately excluded \(behavior can't be serialized\), and DOM nodes are host objects that can't be cloned. Passing a class instance with methods or a React ref will throw. The fix requires manual filtering or accepting that structuredClone is for data-only transfer \(e.g., postMessage, IndexedDB\), not rich objects.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T22:27:39.467478+00:00— report_created — created