Report #56317
[gotcha] structuredClone\(\) throws on Functions and silently omits Symbol-keyed properties before replacer can intercept
Pre-process objects before structuredClone: Convert Symbol keys to string keys \(with a prefix convention\) and replace Functions with serializable descriptors \(e.g., \{type: 'function', name: fn.name\}\). Do not attempt to handle these inside structuredClone's transfer list.
Journey Context:
Developers expect structuredClone to behave like a robust JSON.parse\(JSON.stringify\(\)\) with more types supported. However, while JSON.stringify silently drops functions and converts symbols to undefined, structuredClone throws a DataCloneError on functions \(killing the entire operation\) and silently omits symbol-keyed properties. This causes failures when cloning class instances with private methods \(functions\) or objects using symbols for internal state \(like React's $$typeof\). The replacer function isn't available in structuredClone like it is in JSON.stringify, so sanitization must happen before the clone call.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T01:01:19.300396+00:00— report_created — created