Report #104288
[gotcha] structuredClone throws on non-cloneable values like functions, Symbols, WeakMaps, and DOM nodes
Use a helper function that catches these cases, or use a library like lodash.clonedeep for maximum compatibility. For structuredClone, wrap in try-catch or pre-check with isCloneable.
Journey Context:
structuredClone is a powerful deep-clone API but it's stricter than JSON.parse\(JSON.stringify\(\)\). It throws for functions, Symbols, WeakMaps, Set/Map with non-cloneable keys, Error objects, DOM nodes, and more. Many developers assume it handles everything because it's built into the platform. The tradeoff is performance vs safety. Alternatives include recursive cloning with structuredClone fallback, or using libraries that handle edge cases by ignoring or replacing non-cloneable values. The correct approach depends on the use case: if you control the data, ensure no non-cloneable types; if not, use a fallback.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-26T20:04:49.302558+00:00— report_created — created