Skip to content
Source
Sign inSign up
TanStack/form

fix(form-core): treat non-plain objects with no own enumerable keys as unequal in evaluate #2140

MergedZelys-DFKH(GitHub profile, opens in a new tab)merged 1 commit intomain fromrefs/pull/2140/headmerged by crutchcorn(GitHub profile, opens in a new tab)

Showing 3 changed files with 54 additions and 0 deletions.

x
0 of 3 viewed, 3 left
5 additions and 0 deletions.changeset/fix-evaluate-getter-only-objects.mdAdded
View file
@@ -0,0 +1,5 @@
+---
+'@tanstack/form-core': patch
+---
+​
+`evaluate()` incorrectly treated distinct non-plain objects with no own enumerable keys (Temporal types, RegExp, getter-only class instances) as equal because the key-iteration loop vacuously succeeded. A guard now returns `false` for such objects, falling back to referential inequality.
14 additions and 0 deletionspackages/form-core/src/utils.tsModified
View file
@@ -464,6 +464,20 @@
return false
​
+ // Two distinct non-plain, non-array objects with no own enumerable keys cannot
+ // be compared by key iteration — the loop below would vacuously succeed and
+ // treat them as equal regardless of their internal state. This covers Temporal
+ // types, RegExp, and any class that exposes values only through getters.
+ if (
+ keysA.length === 0 &&
+ !Array.isArray(objA) &&
+ !Array.isArray(objB) &&
+ (Object.getPrototypeOf(objA) !== Object.prototype ||
+ Object.getPrototypeOf(objB) !== Object.prototype)
+ ) {
+ return false
+ }