Report #71073
[gotcha] structuredClone silently strips functions and converts Error instances to plain objects
Do not use structuredClone for objects containing functions \(they are lost\) or Error instances \(use custom serialization to preserve instanceof\). Use lodash cloneDeep for functions or manual mapping for Errors.
Journey Context:
structuredClone is the modern standard for deep cloning \(available in Node 17\+, Deno, Browsers\). It supports cycles, Map, Set, ArrayBuffer, and Date. However, per the HTML spec, it explicitly discards functions \(they disappear\) and clones Error objects by copying message/name/cause but stripping the prototype chain, turning them into plain Objects. This means \`clonedError instanceof Error\` is false. This is a silent data loss bug when cloning API responses or error states for logging.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T01:52:31.704890+00:00— report_created — created