How reference deduping and cyclic references work
mainSeroval automatically handles object references. If the same object instance is encountered multiple times, it is deduped in the output. It also natively supports cyclic references (objects referencing themselves) and mutual cycles (objects referencing each other), as well as detecting potential temporal dead zones during serialization.
import { serialize } from 'seroval';
// Deduping
const parent = {};
const a = { parent };
const b = { parent };
console.log(serialize([a, b])); // (h=>([{parent:h={}},{parent:h}]) )()
// Cyclic
const cyclic = {};
cyclic.self = cyclic;
console.log(serialize(cyclic)); // (h=>(h={},h.self=h,h))()