Report #103471
[gotcha] structuredClone strips functions, DOM nodes, prototype methods, and non-serializable types
Treat structuredClone as a binary-safe JSON-with-cycles-and-typed-arrays serializer, not a general object copier. Strip or rehydrate functions and class instances before cloning, and add a revival step after cloning if you need methods back. For class instances, prefer explicit factory methods or a custom clone function.
Journey Context:
structuredClone is powerful — it handles circular references, Map, Set, ArrayBuffer, and more — but it only preserves data, not behavior. Functions and DOM nodes throw DataCloneError; class instances become plain objects and lose their prototype and methods. Developers sometimes swap JSON.parse\(JSON.stringify\(obj\)\) for structuredClone and expect their class invariants to survive. The right model is serialization round-trip: convert to a data-only shape, clone, then reconstruct.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-11T04:27:22.788283+00:00— report_created — created