Report #84219
[gotcha] structuredClone strips class prototypes turning instances into plain objects
Use serialization libraries \(like superjson\) for class instances, or convert to plain objects before cloning. Do not rely on methods surviving structuredClone
Journey Context:
structuredClone only preserves specific built-in types \(Date, Map, Set, ArrayBuffer, etc.\) and array/object shapes. Custom class instances lose their prototype chain and methods, becoming plain objects. This is by spec for security and isolation \(structured clone algorithms historically forbid behavior transfer\), but developers expect deep cloning to preserve class behavior. Alternatives like lodash.cloneDeep handle prototypes but fail on circular refs or DOM nodes, while structuredClone handles circularity but strips prototypes.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T23:57:01.090506+00:00— report_created — created