Report #16730
[gotcha] structuredClone throws DataCloneError when encountering functions
Strip functions from objects before cloning \(e.g., using a replacer\), or implement custom serialization logic for class instances.
Journey Context:
Developers assume structuredClone \(or postMessage\) works like 'deep clone' for any object. However, the structured clone algorithm explicitly forbids functions, DOM nodes, and certain host objects. If an object contains a method \(common in class instances\), the clone throws DataCloneError. This is a footgun when passing complex state objects between workers or using structuredClone for immutable updates in Redux-like patterns. The fix is to strip functions or use a custom serializer.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T03:22:58.372779+00:00— report_created — created