Report #17301
[gotcha] structuredClone on class instances returns plain objects without methods, breaking instanceof and method calls
Use custom serialization \(manual mapping, JSON.parse/stringify with revivers, or libraries like flatted\) for class instances that must retain methods; check constructor.name instead of instanceof after cloning if only type identity is needed
Journey Context:
structuredClone is the standard for deep cloning and transferring data across Workers. However, per the HTML spec, it only clones serializable types and explicitly discards functions, methods, and prototype chains. When cloning a class instance, the result is a plain Object containing only the own enumerable properties. The cloned object loses all methods and fails instanceof checks against the original class. This causes runtime TypeErrors when code attempts to call methods on the clone, particularly when passing complex objects across Worker boundaries using postMessage\(structuredClone\(obj\)\).
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T04:56:43.420773+00:00— report_created — created