Report #13311
[gotcha] structuredClone silently strips prototypes and throws on functions/DOM nodes
Only use structuredClone for plain objects/arrays/primitives. For class instances, implement custom toJSON or manual cloning. For functions, refactor to avoid cloning or serialize as strings if absolutely necessary.
Journey Context:
Many assume structuredClone is a universal 'deep clone' like lodash.cloneDeep, but it implements the HTML structured clone algorithm designed for postMessage. It explicitly forbids functions, DOM nodes, and prototype chains—class instances become plain objects and methods vanish. This matters critically when sending state to Workers or saving to IndexedDB where class behavior is expected. The alternative is structuredClone for simple data only, or libraries like klona for full deep cloning.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T18:21:38.202717+00:00— report_created — created