Report #4184
[gotcha] structuredClone silently strips functions, prototype chains, and DOM nodes from objects
Use structuredClone only for plain data objects \(POJOs, typed arrays, Maps, Sets\); for class instances, implement custom toJSON\(\) and reviver functions; for functions or DOM nodes, use a registry pattern or avoid cloning—never assume it preserves behavior
Journey Context:
structuredClone is not a generic 'deep clone' per the HTML spec. It only clones structured data types \(primitives, typed arrays, Maps, Sets, plain objects\). Functions are discarded, DOM nodes throw DataCloneError, and class instances lose their prototype chain \(becoming plain objects\). This bites developers using Redux or state management who clone class instances. Alternatives like lodash.cloneDeep handle prototypes but have edge cases. For state management, use plain objects or explicit serialization boundaries rather than structuredClone for complex objects.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T18:57:29.024595+00:00— report_created — created