compareDeep reports unequal Sets as equal

Đang mở
#399 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@Gourav224 đang làm issue này rồi.

Từ ngày 23/10/2026.

  • #400 của @Gourav224 — đang mở

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
30/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
typescript
Lĩnh vực
data

Hướng nghiên cứu

Start in packages/store/src/compare.ts at the deep Set branch and review both one-to-many matching and circular-reference guard behavior. Run the two provided compareDeep reproductions as regression tests, then verify both return false. Note that PR #400 is already open, so this work is currently under way.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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:

  1. Every element of the first Set is checked with [...objB].some(...), so several elements of A can match the same element of B.
  2. 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'

// 1. two elements of A both match B's { x: 1 }
compareDeep(new Set([{ x: 1 }, { x: 1 }]), new Set([{ x: 1 }, { x: 2 }])) // true

// 2. a failed Set-matching attempt (p vs q2) is later treated as equal
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]) // true, even though p !== q2 deeply
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.

Ngôn ngữ chính
TypeScript
Star
913
Fork
121
Merge trung bình
19 giờ 51 phút
Pull request đã merge (30 ngày)
2

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của TanStack/store

Tất cả issue của TanStack/store

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.