fix(form-core): support value types with a custom equals() method in deep equality - #2261
fix(form-core): support value types with a custom equals() method in deep equality#2261FrancoKaddour wants to merge 2 commits into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthrough
ChangesCustom equality support
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/form-core/src/utils.ts`:
- Around line 522-528: Update the constructor-based equality branch in evaluate
to require both objA.equals and objB.equals to be callable before delegating to
objA.equals(objB). Add a test in utils.spec.ts covering an object with equals()
compared against an object without it, asserting they are not considered equal.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 4939f6b5-c10a-44c7-8ff0-7d0e3d405dff
📒 Files selected for processing (3)
.changeset/evaluate-custom-equals.mdpackages/form-core/src/utils.tspackages/form-core/tests/utils.spec.ts
A one-sided equals (e.g. { equals: () => true } vs {}) shares the Object
constructor, so delegating on objA alone let a stray equals property hijack
structural comparison. Per review.
Closes #2195
Problem
evaluate(the deep-equality helper used for dirty-checking) reports two equal value-type instances as unequal. Value types likeTemporal.PlainDate, LuxonDateTime, etc. expose their state through private fields/getters, so they have no own enumerable keys and a non-plain prototype — which hits the no-enumerable-keys guard added in #2140 and returnsfalse. A field backed by such a value is then considered dirty even after it's reset to its original value.Fix
Before that guard, delegate to a custom
equals()method when both operands share a constructor that exposes one. This covers Temporal types, LuxonDateTime, Immutable collections, and any value type following theequals()convention, while leaving plain objects/arrays and the existingDate/Map/Setcases untouched.Tests
Added a
form-coreunit test using a value type with a private field and anequals()method (mirroring Temporal's shape — no own enumerable keys). Reverting the fix fails it; the fullform-coresuite passes, plus typecheck and lint.Summary by CodeRabbit
equals()methods.DateTimeinstances, including objects with private state.