Skip to content

fix(form-core): support value types with a custom equals() method in deep equality - #2261

Open
FrancoKaddour wants to merge 2 commits into
TanStack:mainfrom
FrancoKaddour:fix/evaluate-custom-equals
Open

fix(form-core): support value types with a custom equals() method in deep equality#2261
FrancoKaddour wants to merge 2 commits into
TanStack:mainfrom
FrancoKaddour:fix/evaluate-custom-equals

Conversation

@FrancoKaddour

@FrancoKaddour FrancoKaddour commented Jul 31, 2026

Copy link
Copy Markdown

Closes #2195

Problem

evaluate (the deep-equality helper used for dirty-checking) reports two equal value-type instances as unequal. Value types like Temporal.PlainDate, Luxon DateTime, 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 returns false. 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, Luxon DateTime, Immutable collections, and any value type following the equals() convention, while leaving plain objects/arrays and the existing Date/Map/Set cases untouched.

Tests

Added a form-core unit test using a value type with a private field and an equals() method (mirroring Temporal's shape — no own enumerable keys). Reverting the fix fails it; the full form-core suite passes, plus typecheck and lint.

Summary by CodeRabbit

  • Bug Fixes
    • Improved form value comparisons for objects with custom equals() methods.
    • Added support for value types such as Temporal and Luxon DateTime instances, including objects with private state.
    • Ensured equal instances compare correctly while differing instances remain distinct.

@coderabbitai

coderabbitai Bot commented Jul 31, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 364ea4e4-49c0-4609-a420-4ee4bf3e58c2

📥 Commits

Reviewing files that changed from the base of the PR and between 7ed7642 and c424cca.

📒 Files selected for processing (2)
  • packages/form-core/src/utils.ts
  • packages/form-core/tests/utils.spec.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/form-core/src/utils.ts
  • packages/form-core/tests/utils.spec.ts

📝 Walkthrough

Walkthrough

evaluate now uses callable equals() methods when both objects share a constructor. Tests cover equal and different PlainDate instances and one-sided equals() properties. A patch changeset documents support for custom value types.

Changes

Custom equality support

Layer / File(s) Summary
Custom equality evaluation
packages/form-core/src/utils.ts, packages/form-core/tests/utils.spec.ts, .changeset/evaluate-custom-equals.md
evaluate invokes a callable equals() method before enumerable-key comparison when constructors match. Tests cover matching, nonmatching, and one-sided equals() cases. The changeset documents the patch release.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: support for custom equals methods in form-core deep equality.
Description check ✅ Passed The description explains the problem, fix, tests, and linked issue, but omits the template checklist and release-impact sections.
Linked Issues check ✅ Passed The implementation and tests satisfy issue #2195 by using equals() for same-constructor value types, including Temporal-like instances.
Out of Scope Changes check ✅ Passed The changeset, implementation, and regression tests are directly related to the linked issue and stated pull request objectives.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@FrancoKaddour
FrancoKaddour marked this pull request as ready for review August 3, 2026 12:31

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 5d11281 and 7ed7642.

📒 Files selected for processing (3)
  • .changeset/evaluate-custom-equals.md
  • packages/form-core/src/utils.ts
  • packages/form-core/tests/utils.spec.ts

Comment thread packages/form-core/src/utils.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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Value equality does not handle Temporals

1 participant