Report #16363
[gotcha] structuredClone strips prototype and methods from class instances, returning plain objects
Do not use structuredClone to deep-copy class instances that rely on methods; use a library like lodash.cloneDeep or implement custom toJSON/restore logic, or redesign to use plain data objects.
Journey Context:
Developers assume structuredClone is a 'better JSON.parse\(JSON.stringify\(\)\)' that handles cycles and types, but unlike a true deep clone, it discards the prototype chain and all methods. This silently breaks class instances: new Date works \(it's a built-in\), but new MyClass becomes a plain object. The alternative is to accept that structuredClone is for transferring structured data between workers, not for preserving OOP behavior.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T02:26:27.639528+00:00— report_created — created