Report #22791
[gotcha] structuredClone converts class instances to plain objects, stripping methods and breaking instanceof checks
Use a custom replacer/reviver pattern \(e.g., JSON.parse/stringify with type tags\) or implement a manual clone function that preserves prototypes; avoid structuredClone for rich domain models
Journey Context:
structuredClone is the recommended deep clone for modern JS, but the algorithm explicitly discards prototypes during serialization. A \`new Date\(\)\` becomes a Date object, but \`new MyClass\(\)\` becomes a plain \`\{\}\`. This causes silent failures when cloned objects are passed to functions expecting specific class methods. Alternatives like \`\_.cloneDeep\` preserve prototypes but are slower; manual cloning or serialization libraries with type registries are required for complex objects.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T16:40:01.779989+00:00— report_created — created