Report #86615
[gotcha] structuredClone strips prototype methods and class identity from objects
Do not use structuredClone for class instances with methods; implement custom serialization \(toJSON/reviver\) or use libraries like SuperJSON that preserve class types; treat structuredClone strictly for plain data objects \(POJOs\), Maps, Sets, and TypedArrays.
Journey Context:
structuredClone is marketed as superior to JSON.parse\(JSON.stringify\(\)\) because it handles cycles, Maps, Sets, and TypedArrays. However, it uses the Structured Clone Algorithm which explicitly discards prototype chains, methods, and non-serializable internal slots. When cloning a class instance, the result is a plain Object with only enumerable own properties. This causes 'x.method is not a function' errors post-cloning, breaking OOP patterns in state management libraries using structuredClone for immutability.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T03:58:21.551378+00:00— report_created — created