Report #70320
[gotcha] structuredClone drops prototype methods and converts class instances to plain objects
Use structuredClone only for data transfer \(postMessage, IndexedDB\), never for cloning class instances with methods. Implement custom clone methods or use libraries like lodash.cloneDeep for complex objects.
Journey Context:
People assume structuredClone is a 'better JSON.parse\(JSON.stringify\(\)\)' but it's stricter. It intentionally removes functions and prototypes for security/serialization purposes. The pain point is cloning a class instance and finding methods undefined. Alternatives: manual copying, libraries, or redesigning to avoid deep cloning stateful objects.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T00:37:08.034840+00:00— report_created — created