Report #10705
[gotcha] structuredClone returns plain objects stripping class prototypes and methods
Do not use structuredClone for class instances with methods. Instead, implement custom \`toJSON\(\)\` and \`fromJSON\(\)\` static methods, use a serialization library like \`devalue\` that preserves custom types, or explicitly reconstruct the class instance after cloning by passing the plain object to the constructor.
Journey Context:
When sending class instances via postMessage or cloning for history state, developers expect the methods to survive. structuredClone is explicitly designed for structured data \(Objects, Arrays, Primitives, typed arrays\) and deliberately discards prototypes and functions for security and serialization safety. This is a feature, not a bug, but it silently converts your \`User\` instance into a plain object, causing \`user.save\(\)\` to throw.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T11:22:11.875198+00:00— report_created — created