Summary#
Fixes edge cases in the shallow equality helper:
- Prevents false-positive equality when comparing distinct collection types (e.g.
shallow(new Date(), {}), shallow(new Map(), {}), shallow(new Set(), {}), or shallow(new Map(), new Set()) previously evaluated to true because collection instances have zero own enumerable properties and fell through to empty object keys comparison).
- Correctly treats invalid dates as equal using
Object.is(objA.getTime(), objB.getTime()) (previously NaN !== NaN caused two invalid dates to be considered unequal).
- Added comprehensive unit test suite in
packages/store/tests/shallow.test.ts.
- Added changeset declaring a patch release for
@tanstack/store.
Summary by CodeRabbit#
- Bug Fixes
- Shallow comparisons now return false when comparing a
Map, Set, or Date with a different type.
- Two invalid dates are now considered equal in shallow comparisons, while valid and invalid dates remain unequal.
- Matching Maps and Sets continue to be compared by size and contents. Plain objects, arrays, and other values retain their existing comparison behavior.
Navigate logical layers of code changes, visualize relationships, and explore their blast radius.
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Advanced
Run ID:
06da56b3-1091-4473-ab12-4cdd30f00f24📥 Commits
Reviewing files that changed from the base of the PR and between a9cf2324b4a24a8190ed7981c3be1594e0446872 and b8800606e58360f30ed87431ea4565cc5563a72c.
📒 Files selected for processing (3)
.changeset/fix-shallow-mismatched-types-and-invalid-dates.mdpackages/store/src/shallow.tspackages/store/tests/shallow.test.tsIncluded review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.
📝 Walkthrough
Walkthrough#
The
shallowcomparison now returns false for mismatched Map, Set, or Date types. It compares Date timestamps withObject.is, so two invalid Dates compare equal. Tests cover these cases and other shallow comparisons. A patch changeset records the fixes.Changes#
Shallow comparison
packages/store/src/shallow.ts,packages/store/tests/shallow.test.ts,.changeset/fix-shallow-mismatched-types-and-invalid-dates.mdshallowchecks for mismatched Map, Set, and Date types, and compares Date timestamps withObject.is. Tests cover these behaviors and primitive, reference, object, and array comparisons. A patch changeset records the fixes.Priority: ⬇️ Low
Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Bug fix
Merge Risk: ⚪ Minimal · up to
b8800This change fixes edge cases in the shallow comparison helper and adds tests for them. No merge-blocking risk was found.
Architecture Summary#
Architecture risk: 🔵 Low · up to
b8800The change affects 1 system.
Changed systems:
packages/storeArchitecture concerns No architecture-level concerns identified.
Review details
Systems and components
Before / after behavior
Object.isinstead of!==, making two invalid Dates equal.NaN) and references, and false for differing primitives and nullish mismatches.🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)#
✅ Passed checks (4 passed)
shallowcomparison.Full details: Docstring Coverage
Explanation
Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files. (1 skipped: 1 unsupported.)
✨ 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