Report #7600
[gotcha] structuredClone strips class methods and prototype chain
Use a custom replacer/reviver or library \(e.g., lodash cloneDeep\) if you need to preserve class instances; otherwise, explicitly reconstruct class instances after cloning by mapping the plain object back to the constructor.
Journey Context:
Developers expect structuredClone to be a 'better JSON.parse\(JSON.stringify\(\)\)' for deep cloning. However, it explicitly discards prototypes and methods per the HTML spec, turning class instances into plain objects. This breaks polymorphism after cloning. The alternatives—manual reconstruction or libraries like cloneDeep—trade performance for fidelity. The key realization is that structuredClone is for 'data', not 'objects with behavior'.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T03:14:53.385245+00:00— report_created — created