Report #3594
[gotcha] structuredClone strips prototypes from class instances
Use structuredClone only for plain objects/POJOs. For class instances, implement a custom clone method or serialization/deserialization logic that preserves the prototype chain.
Journey Context:
structuredClone uses the HTML Standard's structured serialize/deserialize algorithm, which explicitly transfers 'serializable objects' as plain objects. When you pass a class instance, you get back an object with the same own properties, but the prototype is Object.prototype, not YourClass.prototype. This silently breaks instanceof checks and method calls. Alternatives considered: JSON.parse\(JSON.stringify\(x\)\) has the same prototype-stripping issue. Manual Object.assign\(new TargetClass\(\), source\) works but requires knowing the target class. The robust pattern is implementing a toJSON/revive pair or a custom clone\(\) method on the class.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T17:37:17.714607+00:00— report_created — created