# Structured clone Resources

## Knowledge

- [WHATWG HTML: §2.7 Safe passing of structured data](https://html.spec.whatwg.org/multipage/structured-data.html)
  Normative home: serializable vs transferable objects, StructuredSerialize / Deserialize (including `forStorage`), transfer, and the `structuredClone(value, options)` API. Use for: any claim when MDN is vague.
- [MDN: The structured clone algorithm](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm)
  What clones (JS types + `[Serializable]` Web/API types), what fails (`DataCloneError`, prototypes, getters/setters, private fields, `RegExp.lastIndex`). Use for: type-matrix lessons and payload design reviews.
- [MDN: Window.structuredClone()](https://developer.mozilla.org/en-US/docs/Web/API/Window/structuredClone)
  Explicit API: `structuredClone(value)` / `{ transfer }`, cycle example, `DataCloneError`. Baseline widely available since March 2022. Use for: when to call the algorithm yourself.
- [MDN: Transferable objects](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Transferable_objects)
  Ownership-move model and transfer list. Use for: large binary / zero-copy designs (already used in the Workers track).
- [web.dev: Deep-copying in JavaScript using structuredClone — Surma](https://web.dev/articles/structured-clone)
  Decision frame: shallow vs JSON hack vs `structuredClone()`. Use for: lesson 1 “when it fits.” **Trust MDN/spec over two 2021 details:** JSON usually *silently loses* `Date`/`Map`/`Set` rather than throwing; `Error` is now cloneable.
- [MDN: JSON.stringify()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
  Authoritative lossiness: cycles and `BigInt` throw; `Date` → ISO string via `toJSON`; `Map`/`Set` → `{}`; functions/`undefined`/symbols dropped or `null`. Use for: contrasting JSON with structured clone — do not guess.
- [MDN: History.pushState()](https://developer.mozilla.org/en-US/docs/Web/API/History/pushState)
  History `state` must be serializable (structured clone / `forStorage`). Use for: implicit clone surfaces.
- [MDN: IndexedDB API](https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API)
  Stored values go through structured clone (`StructuredSerializeForStorage`). Use for: “the platform already clones” vs calling `structuredClone()` yourself.
- [Surma: Is postMessage slow?](https://surma.dev/things/is-postmessage-slow/)
  Measured clone cost, RAIL-ish budgets, patches/chunking/transfer. Use for: when clone cost is the design issue (Workers lesson 3).

## Wisdom (Communities)

- [Stack Overflow — [structured-clone] / JavaScript clone questions](https://stackoverflow.com/questions/tagged/structured-clone)
  `DataCloneError` mysteries, Vue/React proxy traps, “why did my Date become a string.” Use for: production-ish failures — verify against MDN/spec.
- [r/javascript](https://www.reddit.com/r/javascript/)
  Everyday “how do I deep copy” threads. Use for: seeing the JSON-hack habit in the wild; treat recipes as anecdotes.

## Gaps

- No single modern long-form design guide that owns “JSON vs structuredClone vs custom serializer vs transfer” as a system-design chapter. Teach the spectrum from spec + Surma, then the type matrix from MDN.
- `AggregateError` cloning and some Error “interesting properties” (`stack`, `cause`) are still settling in the spec; don’t over-teach Error as a stable wire format.
- SharedArrayBuffer / `forStorage` restrictions are real but out of default path — later lesson only if the mission needs them.
