Report #10518
[gotcha] structuredClone strips prototypes and methods from class instances
Avoid \`structuredClone\` for class instances; instead implement custom \`clone\(\)\` methods using manual property copying with \`Object.create\(Object.getPrototypeOf\(obj\)\)\` and recursive traversal, or use libraries like \`lodash.cloneDeep\` that preserve prototypes
Journey Context:
Developers expect \`structuredClone\` to be a 'better JSON.parse\(JSON.stringify\(\)\)' that handles cycles and typed arrays, but the Structured Clone Algorithm explicitly discards prototypes and functions for security and serialization consistency \(since the target realm might not have the same classes\). The alternative \(manual cloning\) preserves the prototype chain but loses the cycle detection and native typed array handling that structuredClone provides. The trade-off is between structural fidelity and object graph complexity.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T10:52:21.573505+00:00— report_created — created