Report #59065
[gotcha] structuredClone strips prototype and methods from class instances
Use structuredClone only for plain objects/maps/sets; for class instances, implement custom toJSON/fromJSON methods or use libraries like lodash.cloneDeep with customizers to re-hydrate prototypes after cloning.
Journey Context:
structuredClone is often misunderstood as a 'better deep clone' but it aggressively serializes to the Structured Clone Algorithm format, discarding prototypes, methods, and non-serializable properties like functions. Developers expect \`clone instanceof MyClass\` to be true, but it returns false because the prototype chain is lost. While \`JSON.parse\(JSON.stringify\(\)\)\` drops undefined and Maps, structuredClone preserves Maps but still kills methods. The only robust path is to accept that structuredClone produces plain data and manually reconstruct class instances, or use a library that handles prototypal copying via customizers.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T05:37:36.747286+00:00— report_created — created