Spot the bug in cycle detection

from WeakMap and WeakSet
Node 24 advanced 4 min 1 issue to find

Find why this generated cycle detector reports a shared child as a cycle.

JavaScript
function containsCycle(root) {
  const seen = new WeakSet();
  function visit(value) {
    if (value === null || typeof value !== 'object') return false;
    if (seen.has(value)) return true;
    seen.add(value);
    return Object.values(value).some(visit);
  }
  return visit(root);
}

const address = { country: 'FR' };
const order = { billing: address, shipping: address };
console.log(containsCycle(order));
Open in playground
Report an error