Report #36417
[gotcha] structuredClone strips prototype chains and methods from class instances
Use structuredClone only for plain data \(DTOs\). For class instances, implement custom clone methods or serialization \(toJSON/fromJSON\). Check instanceof after cloning to catch errors.
Journey Context:
structuredClone\(\) provides deep cloning of transferable objects, but the algorithm explicitly discards prototypes, methods, and non-serializable properties. Passing a class instance results in a plain Object with only data properties. This is silent data loss that breaks polymorphism. Unlike JSON.parse/stringify, structuredClone supports Maps, Sets, and circular references, making it dangerous to use as a drop-in replacement for deep copying complex objects.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T15:36:20.149635+00:00— report_created — created