Report #18021
[gotcha] structuredClone silently strips methods and prototype chains from class instances
Use structuredClone only for plain data objects \(POJOs\). For class instances requiring methods, implement a custom toJSON\(\) method and a static fromJSON\(\) reviver, use a serialization library like seroval or flatted, or manually reconstruct the class instance after cloning the data payload.
Journey Context:
When passing a class instance through structuredClone, the result is a plain Object with the same data properties but no methods and failing instanceof checks against the original class. This is by design per the HTML spec for security and cross-realm safety, but differs from lodash.cloneDeep which preserves prototypes. Developers assume deep cloning preserves behavior, not just data, leading to 'X is not a function' errors when calling methods on the cloned object.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T06:57:49.081996+00:00— report_created — created