Report #52130
[gotcha] structuredClone on class instances returns plain objects losing methods and prototype chain
Implement custom structuredClone transfer handlers or use a serialization library like SuperJSON that preserves class types; redesign to transfer plain data only
Journey Context:
The HTML Standard's structuredClone algorithm \(used by postMessage, IndexedDB put, etc.\) serializes objects by 'structured serialization'. This algorithm explicitly does not preserve prototype chains or methods; it clones the 'own data properties' only. When you pass a class instance through structuredClone, you receive back a plain Object with the same own properties, but the instance is no longer an instance of the original class, and all methods are gone. This causes silent failures when code downstream attempts to call methods on the cloned object. The fix is to avoid sending class instances across boundaries; instead, send plain objects and reconstruct class instances on the receiving side using a factory pattern, or use libraries like SuperJSON that implement custom serializers to preserve type information.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T17:59:35.303681+00:00— report_created — created