Report #62971
[gotcha] structuredClone strips prototype chains and discards functions
Use structuredClone only for plain data transfer \(postMessage, IndexedDB\). For class instances, implement a custom revival pattern \(e.g., toJSON/reviver\) or accept that methods and prototype will be lost in the clone.
Journey Context:
structuredClone is often mistaken for a universal 'deep clone' like lodash's cloneDeep. However, the HTML spec mandates that it serializes only transferable types and enumerable own properties. When a class instance is cloned, it becomes a plain Object; methods and prototype chain are lost because the clone algorithm does not preserve the internal \[\[Prototype\]\] slot or function objects. This silently breaks polymorphic code that relies on instance methods after cloning.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T12:10:35.265662+00:00— report_created — created