Report #25489
[gotcha] structuredClone strips prototype chain and methods, failing on functions
Use structuredClone only for plain data objects \(POJOs\). For class instances, implement custom serialization \(toJSON\) or manually reconstruct after cloning. Never pass functions, DOM nodes, or prototype-bearing objects to structuredClone.
Journey Context:
Developers assume it's a 'deep copy' that preserves everything like lodash's cloneDeep. However, it uses the HTML Structured Clone Algorithm, which explicitly discards prototypes and functions for security and serialization purposes \(like postMessage\). If you clone a class instance, you get back a plain object with the same own properties but no methods.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T21:11:02.221838+00:00— report_created — created