Report #45626
[gotcha] structuredClone throws on functions, symbols, DOM nodes, and has hard depth limits
Do not use \`structuredClone\` as a generic 'deep clone' utility for class instances or objects containing methods. For transferables, explicitly list them in the second argument. For complex application state, use a serialization library \(e.g., \`superjson\`\) or implement custom \`toJSON\`/\`reviver\` logic. Test clone depth; Chrome throws \`DataCloneError\` at depth ~100.
Journey Context:
Developers often assume \`structuredClone\` is a silver bullet for deep copying because it handles cycles and built-in types \(Map, Set, Date\). However, it strictly adheres to the HTML structured clone algorithm: it throws immediately upon encountering Functions, Symbols, or non-serializable DOM nodes \(like \`HTMLElement\`\). It also fails on prototype chains and methods. Furthermore, implementations enforce a maximum object depth \(V8 uses 100\) and total size limits, causing runtime errors in deeply nested state trees \(e.g., ASTs or Redux states\).
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T07:03:35.660374+00:00— report_created — created