Report #55408
[gotcha] structuredClone strips prototypes and methods from class instances
Use class instance revival pattern with structuredClone \(transfer option\) or implement custom toJSON/reviver, avoid structuredClone for class hierarchies
Journey Context:
structuredClone is a deep clone using the Structured Clone Algorithm \(SCA\) from the HTML spec. SCA serializes to a structured format that preserves cyclic references, typed arrays, and some platform types, but it does NOT preserve prototypes or methods. When you clone a class instance, you get a plain Object with the same own properties but losing all methods and instanceof checks. Common wrong assumption: it's like lodash.cloneDeep which can preserve classes. If you need prototypes, alternatives: manual copy constructor, lodash.cloneDeep with customizer, or implement a revival pattern where you store \_\_type in the clone and reconstruct post-transfer. For worker communication, use Transferable objects explicitly. Always treat structuredClone output as plain data, not instances.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T23:29:32.367233+00:00— report_created — created