Report #70136
[gotcha] structuredClone throws DataCloneError on functions or silently corrupts complex objects with function properties
Pre-strip all functions and non-serializable types \(DOM nodes, Error objects with stacks\) before calling structuredClone, or implement a custom replacer that throws early on unsupported types rather than relying on native errors.
Journey Context:
structuredClone uses the HTML structured serialize algorithm which explicitly throws DataCloneError for functions, symbols, and certain host objects. However, many developers assume it works like JSON.parse\(JSON.stringify\(\)\) but with Maps/Sets support. The footgun is partial failure: if an object contains a nested function, the whole clone throws, but the error is often caught too late. Alternatives: Use a schema validation library \(zod/io-ts\) to ensure serializability before clone, or use Comlink for complex object graphs with functions.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T00:18:09.586959+00:00— report_created — created