fix(form-core): treat non-plain objects with no own enumerable keys as unequal in evaluate #2140
main fromrefs/pull/2140/head·merged by crutchcorn(GitHub profile, opens in a new tab) 🎯 Changes#
Fixes #1628.
evaluate() compares objects by iterating Object.keys(). That works fine for plain objects, but for anything whose state lives only in getters, Object.keys() returns []. The key-iteration loop then vacuously succeeds and two distinct instances are treated as equal, regardless of what they actually contain. Temporal.Duration, RegExp, any class that exposes values through getters — they all hit this. The result is that form updates get dropped silently when a field value changes to a new instance of such a type.
The fix is a single guard placed after the key-count check:
if (
keysA.length === 0 &&
!Array.isArray(objA) &&
!Array.isArray(objB) &&
(Object.getPrototypeOf(objA) !== Object.prototype ||
Object.getPrototypeOf(objB) !== Object.prototype)
) {
return false
}
When both objects have zero own enumerable keys and at least one isn't a plain {}, they fall back to referential inequality (Object.is at the top already returned false). Arrays get an explicit carve-out so evaluate([], []) still returns true.
PR #1939 adds a specific instanceof Blob guard for File/Blob. This guard is more general and covers the same case, plus Temporal, RegExp, Error, and anything else with a getter-only design. If #1939 merges first, its instanceof Blob check fires before reaching this one, so there's no conflict. If this merges first, File/Blob is already covered.
One thing to flag: two RegExp literals with identical source and flags (like /abc/g vs /abc/g) now return false, since they're different instances. Previously they returned true vacuously, which was also wrong: it suppressed updates when a regex field actually changed. The behavior is now in the right direction. A dedicated instanceof RegExp handler (like the existing Date one) could add semantic equality if that turns out to be useful.
✅ Checklist#
- I have followed the steps in the Contributing guide.
- I have tested this code locally with
pnpm test:pr.
🚀 Release Impact#
- This change affects published code, and I have generated a changeset.
- This change is docs/CI/dev-only (no release).
Summary by CodeRabbit#
Release Notes#
- Bug Fixes
- Fixed form validation comparison logic that was incorrectly treating distinct non-plain objects as equivalent. This affected special object types including Temporal, RegExp, and classes with getter-only properties.
- Strengthened test coverage to ensure accurate object comparison behavior across all supported object types.
- 1
crutchcorn(GitHub profile, opens in a new tab) approved these changes
This is great, thanks!
View your CI Pipeline Execution ↗ for commit 1b02d5993370eb040014b78e2cb022c2db9bd325
Command Status Duration Result nx affected --targets=test:sherif,test:knip,tes...✅ Succeeded 2m 13s View ↗ nx run-many --target=build --exclude=examples/**✅ Succeeded 33s View ↗
☁️ Nx Cloud last updated this comment at
2026-05-10 19:48:52UTCMore templates
- @tanstack/form-example-angular-array
- @tanstack/form-example-angular-large-form
- @tanstack/form-example-angular-simple
- @tanstack/form-example-angular-standard-schema
- @tanstack/form-example-react-array
- @tanstack/form-example-react-compiler
- @tanstack/form-example-react-composition
- @tanstack/form-example-react-devtools
- @tanstack/form-example-react-dynamic
- @tanstack/field-errors-from-form-validators
- @tanstack/form-example-react-large-form
- @tanstack/form-example-react-next-server-actions
- @tanstack/form-example-react-next-server-actions-zod
- @tanstack/form-example-react-query-integration
- @tanstack/form-example-remix
- @tanstack/form-example-react-simple
- @tanstack/form-example-react-standard-schema
- @tanstack/form-example-react-tanstack-start
- @tanstack/form-example-react-ui-libraries
- @tanstack/form-example-lit-array
- @tanstack/form-example-lit-simple
- @tanstack/form-example-lit-standard-schema
- @tanstack/form-example-lit-ui-libraries
- @tanstack/form-example-solid-array
- @tanstack/form-example-solid-devtools
- @tanstack/form-example-solid-large-form
- @tanstack/form-example-solid-simple
- @tanstack/form-example-solid-standard-schema
- @tanstack/form-example-svelte-array
- @tanstack/form-example-svelte-large-form
- @tanstack/form-example-svelte-simple
- @tanstack/form-example-svelte-standard-schema
- @tanstack/form-example-vue-array
- @tanstack/form-example-vue-simple
- @tanstack/form-example-vue-standard-schema
@tanstack/angular-form
npm i https://pkg.pr.new/@tanstack/angular-form@2140@tanstack/form-core
npm i https://pkg.pr.new/@tanstack/form-core@2140@tanstack/form-devtools
npm i https://pkg.pr.new/@tanstack/form-devtools@2140@tanstack/lit-form
npm i https://pkg.pr.new/@tanstack/lit-form@2140@tanstack/react-form
npm i https://pkg.pr.new/@tanstack/react-form@2140@tanstack/react-form-devtools
npm i https://pkg.pr.new/@tanstack/react-form-devtools@2140@tanstack/react-form-nextjs
npm i https://pkg.pr.new/@tanstack/react-form-nextjs@2140@tanstack/react-form-remix
npm i https://pkg.pr.new/@tanstack/react-form-remix@2140@tanstack/react-form-start
npm i https://pkg.pr.new/@tanstack/react-form-start@2140@tanstack/solid-form
npm i https://pkg.pr.new/@tanstack/solid-form@2140@tanstack/solid-form-devtools
npm i https://pkg.pr.new/@tanstack/solid-form-devtools@2140@tanstack/svelte-form
npm i https://pkg.pr.new/@tanstack/svelte-form@2140@tanstack/vue-form
npm i https://pkg.pr.new/@tanstack/vue-form@2140commit:
1b02d59Codecov Report#
:white_check_mark: All modified and coverable lines are covered by tests. :white_check_mark: Project coverage is 90.29%. Comparing base (
6892ed0) to head (1b02d59). :warning: Report is 200 commits behind head on main.Additional details and impacted files
@@ Coverage Diff @@ ## main #2140 +/- ## ========================================== - Coverage 90.35% 90.29% -0.07% ========================================== Files 38 49 +11 Lines 1752 2050 +298 Branches 444 538 +94 ========================================== + Hits 1583 1851 +268 - Misses 149 179 +30 Partials 20 20:umbrella: View full report in Codecov by Sentry. :loudspeaker: Have feedback on the report? Share it here.
:rocket: New features to boost your workflow:
- :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
- :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
crutchcorn(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID:
70aa1d66-a278-41d6-b7eb-9a24ebc591e9📥 Commits
Reviewing files that changed from the base of the PR and between 93be6f01ba07c290dbec34d6c170f79e9eb2dfef and 1b02d5993370eb040014b78e2cb022c2db9bd325.
📒 Files selected for processing (3)
.changeset/fix-evaluate-getter-only-objects.mdpackages/form-core/src/utils.tspackages/form-core/tests/utils.spec.ts📝 Walkthrough
Walkthrough#
This patch fixes the
evaluate()function in@tanstack/form-coreto correctly distinguish non-plain objects with zero own enumerable keys (such as Temporal types, RegExp, Date, or getter-only class instances) by returningfalseinstead of treating them as equal, preventing silent form option update failures.Changes#
.changeset/fix-evaluate-getter-only-objects.md@tanstack/form-coredocumenting the fix forevaluate()incorrectly treating distinct non-plain objects as equal.packages/form-core/src/utils.tsevaluate()that returnsfalsewhen both inputs are non-array objects with no own enumerable keys and non-Object.prototypeprototypes, preventing false positives from key iteration never executing.packages/form-core/tests/utils.spec.tsEstimated code review effort#
🎯 2 (Simple) | ⏱️ ~10 minutes
Poem#
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)#
✅ Passed checks (4 passed)
#1628by implementing the required guard to prevent distinct non-plain objects with no enumerable keys from being treated as equal.✨ 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.
❤️ Share