Describe the bug#
compareDeep can report two different Sets as equal. There are two causes, both in the deep Set branch of packages/store/src/compare.ts:
- Every element of the first Set is checked with
[...objB].some(...), so several elements of A can match the same element of B.
- The circular-reference guard adds each
(a, b) pair to seen and never removes it. When a .some() attempt fails, the pair stays recorded, so a later comparison of that same pair returns true straight away.
Steps to Reproduce the Bug or Issue#
import { compareDeep } from '@tanstack/store'
compareDeep(new Set([{ x: 1 }, { x: 1 }]), new Set([{ x: 1 }, { x: 2 }]))
const p = { x: 1 }, q = { x: 2 }
const p2 = { x: 1 }, q2 = { x: 2 }
compareDeep([new Set([p, q]), p], [new Set([q2, p2]), q2])
Expected behavior#
Both calls return false.
Platform#
@tanstack/store main (53f30be), Node 26
Additional context#
I have a fix with tests ready and will open a PR.