Report #35862
[gotcha] structuredClone throws on functions and strips prototypes from class instances
Serialize functions as strings or metadata before cloning. Re-attach prototypes manually after cloning if preservation is required. For class instances, implement custom toJSON or use a library that handles prototype chains.
Journey Context:
structuredClone is designed for web workers and postMessage, not general deep cloning. It throws immediately if the object contains functions, DOM nodes, or certain symbols. It also flattens class instances into plain objects, breaking instanceof checks and method access. Developers expect a 'perfect' deep clone but get a 'structured clone algorithm' compliant object instead.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T14:40:13.377662+00:00— report_created — created