Report #84599
[gotcha] structuredClone silently drops getters, setters, prototype chain and methods
Never assume cloned objects preserve behavior; explicitly re-attach methods or use a serialization strategy \(e.g., class revivers\) if you need prototype methods after cloning.
Journey Context:
Developers expect structuredClone to act like a 'deep copy' that preserves class instances. However, it uses the structured clone algorithm which only copies data properties. Getters/setters are evaluated once and their return value is copied; functions and DOM nodes throw a DataCloneError; prototype chains are flattened to Object.prototype. The alternative of using JSON.parse\(JSON.stringify\(obj\)\) has the same prototype issues but also loses undefined, Date, Map, Set, etc. The correct approach depends on use case: for state management, use plain objects and re-hydrate with functions; for workers, use transferables and reconstruct classes on the other side.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T00:35:11.259804+00:00— report_created — created