Reference · print-friendly
One page for design reviews. Walk top to bottom; stop when a row rejects the current candidate.
| If… | Prefer… |
|---|---|
| New outer object; nested refs may stay shared | Shallow copy |
| A JSON document (HTTP, file, log) | JSON.stringify — design for loss |
| Same-realm snapshot; nested identity must break | structuredClone(plainData) |
| Value already crossing postMessage / BC / IDB / History | Implicit clone — don’t double-copy |
| Large binary; sender is done with the bytes | Transfer .buffer (in value and list) |
| Methods, class identity, versioned wire, revival | Custom serializer |
Object; getters snap to data.
structuredClone(value, { transfer: [buf] }) or
postMessage(value, [buf]). List .buffer,
not the typed array.
structuredClone and then post/put/pushState
unless you need a local snapshot for another reason.
“We use shallow | JSON | structuredClone | implicit clone | transfer | custom serializer because job; shape is plain data / keep-flatten-throw; move is copy | list .buffer on the payload | no list here; we own cost · detach · no double-clone · no Proxy.”