Report #52297
[gotcha] structuredClone throws on functions and symbols rather than stripping them like JSON.stringify
Before cloning, recursively traverse and strip functions and symbols, or replace them with serializable placeholders. For functions, consider storing references in a registry and replacing with IDs. For symbols, use Symbol.keyFor\(\) for registered symbols or property keys.
Journey Context:
Unlike JSON.stringify which silently drops functions and symbols, structuredClone throws a DataCloneError immediately upon encountering them. This makes it unsuitable for cloning objects with methods or symbol-keyed properties without preprocessing. The algorithm also rejects certain platform objects like DOM nodes. Understanding the structured clone algorithm's transfer list and error handling is crucial for robust state management in Web Workers or IndexedDB.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T18:16:23.879416+00:00— report_created — created