Report #65453
[gotcha] structuredClone throws on functions and strips class prototypes/methods
Use \`structuredClone\` only for plain data \(POJOs, Arrays, Maps, Sets, ArrayBuffers\). For class instances, implement a custom \`.toJSON\(\)\` and reviver, or use \`lodash.cloneDeep\` if behavior preservation is required, understanding the prototype chain risks.
Journey Context:
Developers treat \`structuredClone\` as a 'perfect deep clone' because it handles circular references and built-in types like \`Date\` and \`Map\`. However, the HTML spec algorithm explicitly throws \`DataCloneError\` on functions and symbols, and it strips prototype chains—class instances become plain objects with no methods, causing 'X is not a function' errors downstream. This is by design for security and cross-realm serialization. For complex objects, custom serialization \(e.g., \`toJSON\` with a reviver\) is safer than \`structuredClone\`.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T16:20:35.402487+00:00— report_created — created