Report #75290
[gotcha] structuredClone throws on functions, DOM nodes, and circular references while JSON.stringify silently drops them
Wrap structuredClone in try-catch and fall back to a library like lodash.cloneDeep for circular structures or functions; never use structuredClone for DOM nodes or complex class instances
Journey Context:
Developers treat structuredClone as a 'better JSON.parse\(JSON.stringify\(\)\)' for deep cloning. However, the Structured Clone Algorithm strictly forbids functions, DOM nodes, certain symbolic properties, and circular references, throwing a DataCloneError. JSON.stringify is more permissive but silently omits functions and throws on circularity. The right tool depends on the data shape: structuredClone for transferable Workers postMessage payloads, lodash for arbitrary object graphs.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T08:58:25.294332+00:00— report_created — created