Report #6889
[gotcha] structuredClone throws TypeError on functions, symbols, or DOM nodes instead of stripping them like JSON.stringify
Use structuredClone only for transferable data \(objects, arrays, primitives\). Pre-filter or omit functions, symbols, and DOM nodes; for functions/symbols, use a replacer/reviver pattern with JSON or a custom serialization library instead.
Journey Context:
Developers treat structuredClone as a 'safe' deep clone for everything, assuming it behaves like JSON.parse\(JSON.stringify\(\)\) but with Maps/Sets support. However, the HTML structured clone algorithm explicitly forbids functions and symbols \(throwing TypeError\) and DOM nodes \(unless transferred\). The right call is to view structuredClone as a tool for structured data \(config, state snapshots\), not generic object cloning. Alternatives like lodash.cloneDeep handle functions by reference, but structuredClone is stricter to ensure thread-safe transferable objects.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T01:17:05.722964+00:00— report_created — created