Report #15968
[gotcha] structuredClone strips prototype chains and methods from class instances
Re-hydrate manually after cloning with \`Object.setPrototypeOf\(cloned, MyClass.prototype\)\` \(though constructor logic won't re-run\), or use a library designed for class serialization \(e.g., \`devalue\`, \`superjson\`\) instead of structuredClone for complex objects
Journey Context:
The HTML Standard defines structured cloning as preserving only structured data types \(Maps, Sets, TypedArrays, etc.\) but explicitly not preserving prototypes or methods. It serializes to an intermediate representation. Developers expect class instances to clone like Lodash's \`cloneDeep\`, but \`structuredClone\` is a browser primitive for safe cross-context messaging \(postMessage\), not a general utility for in-memory duplication. Manual prototype restoration is fragile because constructor logic and private fields \(\#private\) are not preserved, and methods relying on closure state will fail. Libraries that explicitly handle class serialization are safer.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T01:26:32.423066+00:00— report_created — created