isEqual throws on Temporal values because it calls valueOf
Chưa có ai nhận issue này.
Đá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
- 82/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- javascript, node.js
- Lĩnh vực
- frontend, testing-qa
Hướng nghiên cứu
Bắt đầu trong index.js, khoảng dòng 80, nơi isEqual so sánh các giá trị bằng valueOf() trước toString(). Tái hiện vấn đề bằng các ví dụ Temporal.PlainTime trong issue, bao gồm cả các giá trị lồng nhau, và kiểm tra hành vi hiện có của Date và RegExp. Hoàn tất khi các giá trị Temporal khác nhau nhưng bằng nhau được so sánh là true, các giá trị khác nhau được so sánh là false, và các phép so sánh lồng nhau trả về boolean mà không làm thay đổi hành vi của Date hoặc RegExp.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Is there an existing issue for this?
- I have searched the existing issues
Code of Conduct
- I agree to follow this project's Code of Conduct
Code Sandbox link
No response
Bug report
## Description
`isEqual` throws when comparing two distinct Temporal values (or objects that contain them). `Temporal.*.prototype.valueOf` is specified to throw a `TypeError` so that `<` and `>` cannot be used by accident. Equality is supposed to go through `equals` or `compare`.
`react-fast-compare` 3.2.2 calls `valueOf` whenever an object overrides it, before the `toString` fallback:
if (a.valueOf !== Object.prototype.valueOf && typeof a.valueOf === 'function' && typeof b.valueOf === 'function') return a.valueOf() === b.valueOf();
if (a.toString !== Object.prototype.toString && typeof a.toString === 'function' && typeof b.toString === 'function') return a.toString() === b.toString();
`index.js`, around line 80. The `toString` line is never reached. Temporal’s `toString()` returns a stable ISO string and does not throw, so that fallback would compare these values correctly. `Date` can keep using `valueOf()`, which returns a number and does not throw.
The same reference still compares equal, because of the `a === b` check at the start. The throw only happens for two different instances, including two instances of the same time.
## Reproduction
Node 26, with Temporal built in. `[email protected]`.
const isEqual = require("react-fast-compare");
const a = Temporal.PlainTime.from("07:00");
const b = Temporal.PlainTime.from("07:00");
isEqual(a, a); // true
isEqual(a, b); // TypeError
isEqual({ time: a }, { time: b }); // TypeError
Actual message:
TypeError: Do not use Temporal.PlainTime.prototype.valueOf; use Temporal.PlainTime.prototype.compare for comparison.
The same throw happens for `PlainDate`, `PlainDateTime`, `Instant`, `ZonedDateTime`, and `Duration`.
## Expected
`isEqual` returns a boolean.
- `isEqual(a, b)` is `true` when the two times represent the same time.
- `isEqual(a, Temporal.PlainTime.from("08:00"))` is `false`.
- Nested values behave the same way.
- `Date` and `RegExp` keep their current behavior.
## Context
`@carbon/react` 1.118 depends on `react-fast-compare@^3.2.2`. Its `DataTable` deep-compares row cell values with `isEqual`. A cell that holds a domain object containing a `Temporal.PlainTime` crashes the table when those instances are not the same reference. Carbon’s ComboBox and multi-select use the same comparison.
## Suggested fix
If `valueOf()` throws, fall through to the existing `toString()` comparison instead of failing the whole `isEqual` call. That keeps `Date` on `valueOf()` and lets Temporal use its ISO `toString()`.
- Ngôn ngữ chính
- JavaScript
- Star
- 1.7k
- Fork
- 54
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của FormidableLabs/react-fast-compare
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 45/100
-
Add ability to compare functionsCó thể đã có người làm @quantizor đã nhận 1472 ngày trước. Đang mở
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
FormidableLabs/react-fast-compare#114 · 9 bình luận ·
-
Audit security alertsĐang mởinvestigate
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 25/100
FormidableLabs/react-fast-compare#70 · 2 bình luận ·
-
enhancement
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 30/100
FormidableLabs/react-fast-compare#68 · 11 reaction ·
-
upstream
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
FormidableLabs/react-fast-compare#50 · 6 bình luận ·
Tất cả issue của FormidableLabs/react-fast-compare
Issue tương tự
-
[guide] AGENTS.md claims the coverage gate, e2e and full lint run on every PR after ADR 0011 focused validationCó thể đã có người làm @hivecommons-hive đã nhận hôm nay. Đang mởagent/guide documentation hive/claimed-by-guide stage/040-covered-by-pr
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 81/100
cncf/endusers#2006 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
check:passed feeds:add
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
Maintainer thường phản hồi trong vòng 4 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
all-contributors/cli#587 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
RGAA5
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
Maintainer thường phản hồi trong vòng 8 ngày
-
feedback simulation workshop
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
githubnext/gh-aw-workshop#5157 ·
Maintainer thường phản hồi trong vòng 1 ngày