Report #74454
[gotcha] structuredClone silently strips methods and prototype chains from class instances
For objects requiring preserved methods or class identity, use a custom serialization library \(e.g., SuperJSON\) or implement \`toJSON\`/\`reviver\` logic instead of structuredClone.
Journey Context:
structuredClone is specified in the HTML Standard to only clone "serializable" types, which explicitly excludes functions and prototype chains. When a class instance is cloned, it becomes a plain Object with the same data properties, but loses its prototype, methods, getters/setters, and private fields. Developers often assume it behaves like Lodash's cloneDeep or manual JSON.parse\(JSON.stringify\(\)\), but it is stricter and different \(e.g., it handles Map/Set/ArrayBuffer but not functions\). Using structuredClone on domain models with behavior \(methods\) results in objects that throw TypeError when methods are called, or silently fail instanceof checks.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T07:34:09.314228+00:00— report_created — created