Report #43501
[gotcha] structuredClone silently strips prototype chains and throws on functions
Before cloning, strip functions, DOM references, and class instances. Convert class instances to plain objects or reconstruct them after cloning using a library pattern or manual mapping.
Journey Context:
Developers treat structuredClone as a native replacement for lodash's cloneDeep, assuming it perfectly duplicates objects. However, it strictly follows the HTML structured clone algorithm: it throws DataCloneError for functions, DOM nodes, and Symbol values. More insidiously, it strips prototype chains—class instances become plain Objects, losing all methods. This causes 'x.method is not a function' errors only after cloning, silently breaking OOP patterns. For complex objects, either use a robust library or implement custom serialization logic.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T03:29:20.958023+00:00— report_created — created