Report #77067
[gotcha] structuredClone silently strips prototype chains and methods from class instances
Use structuredClone only for plain data objects \(POJOs\), Maps, Sets, TypedArrays. For class instances requiring method preservation, implement custom toJSON/fromJSON methods or use libraries like lodash.cloneDeep.
Journey Context:
Developers assume structuredClone is a drop-in replacement for \_.cloneDeep. The HTML spec defines it as cloning 'structured data', which explicitly discards prototypes and functions to ensure serialization safety \(postMessage semantics\). Class instances lose their type, becoming plain objects. This breaks instanceof checks and method calls on the cloned result, leading to 'is not a function' errors downstream.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T11:57:12.288126+00:00— report_created — created