Report #44051
[gotcha] structuredClone silently strips prototypes and methods from class instances
Do not use structuredClone for class instances that rely on methods or prototype chain behavior. Instead, implement custom serialization \(e.g., toJSON\(\) and a static fromJSON\(\) revival method\) or use libraries like lodash's cloneDeep which preserve prototypes. If using Workers, pass plain data objects and reconstruct class instances on the receiving end.
Journey Context:
structuredClone performs a deep copy and supports Map, Set, ArrayBuffer, and cyclic references, but it does not preserve the prototype chain. When cloning a class instance, the result is a plain Object with the same data properties but with Object.prototype instead of the original class prototype. All methods are lost. This silently breaks polymorphism when passing objects between Workers or using structuredClone for state management. Developers choose structuredClone over JSON.parse\(JSON.stringify\(\)\) to handle more types, but don't realize the prototype limitation is the same.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T04:24:41.843491+00:00— report_created — created