Report #4941
[gotcha] structuredClone strips custom class prototypes turning instances into plain objects
Only use structuredClone for plain objects, Maps, Sets, Arrays, and TypedArrays. For class instances requiring methods, implement a custom .toJSON\(\) or serialization method, or use a library that preserves class hierarchies.
Journey Context:
Developers assume deep cloning preserves methods. structuredClone intentionally copies only own enumerable properties per the HTML spec, dropping the prototype chain to avoid executing foreign code during deserialization. Alternatives like lodash.cloneDeep preserve prototypes but have security risks. The tradeoff is safety \(no prototype pollution\) vs convenience.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T20:19:46.715224+00:00— report_created — created