Report #71524
[gotcha] structuredClone loses class methods and prototype chains during serialization
Use structuredClone only for plain objects/DTOs; for class instances implement custom toJSON\(\) or a static fromJSON\(\) factory to reconstruct the instance with its prototype
Journey Context:
Developers treat structuredClone as a 'universal deep clone' expecting it to preserve class instances, but the HTML spec explicitly forbids functions and prototype chains in the serialization algorithm, returning a plain Object with only own enumerable properties. Alternatives like lodash.cloneDeep preserve prototypes but are slower and risk prototype pollution. For Data Transfer Objects structuredClone is correct; for Domain Models with behavior, manual reconstruction or factory patterns are required to restore methods.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T02:37:45.424414+00:00— report_created — created