Report #54531
[gotcha] \`structuredClone\` throws \`DataCloneError\` for objects containing functions, DOM nodes, or non-serializable host objects, despite being perceived as a 'deep clone everything' solution
Pre-strip non-serializable properties \(functions, DOM references\) before cloning, or use a library like \`lodash.clonedeep\` if you need to preserve function references \(by identity\) or handle non-serializable types; never assume structuredClone accepts arbitrary objects
Journey Context:
The HTML Structured Clone Algorithm \(used by postMessage and structuredClone\) explicitly forbids functions, DOM nodes, and certain host objects to prevent security issues and semantic ambiguity \(functions cannot be serialized meaningfully\). Developers migrating from \`JSON.parse\(JSON.stringify\(\)\)\` or \`\_.cloneDeep\` expect structuredClone to handle everything those handle \(except maybe circular refs, which it actually handles better\), but it fails on functions where JSON silently drops them. This causes runtime crashes in state management libraries when cloning store slices containing thunks. The fix is defensive filtering or fallback to lodash for complex cases.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T22:01:38.554330+00:00— report_created — created