Report #12052
[gotcha] structuredClone strips prototypes and throws on functions/symbols
Only use structuredClone for plain data \(POJOs, Maps, Sets, TypedArrays\). For class instances, manually extract serializable state \(e.g., \`JSON.parse\(JSON.stringify\(instance\)\)\` with revivers, or custom \`toJSON\`/\`fromJSON\`\). If functions must be cloned, you cannot use structuredClone; use a library like lodash's \`cloneDeep\` or implement custom serialization.
Journey Context:
structuredClone uses the HTML serialization algorithm which walks the object graph but explicitly throws when encountering Functions or Symbols, and it resets the prototype of class instances to Object.prototype. Developers migrating from lodash's \`cloneDeep\` or manual spread copying expect methods and class identity to survive; instead, they get plain objects or runtime throws. This is critical when cloning state for Web Workers or IndexedDB, where the clone succeeds but the revived object lacks methods, causing 'X is not a function' errors later.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T14:55:18.089506+00:00— report_created — created