Skip to content

fix(react): use Object.is instead of === in defaultCompare#298

Open
alex-js-ltd wants to merge 6 commits intoTanStack:mainfrom
alex-js-ltd:fix/default-compare-object-is
Open

fix(react): use Object.is instead of === in defaultCompare#298
alex-js-ltd wants to merge 6 commits intoTanStack:mainfrom
alex-js-ltd:fix/default-compare-object-is

Conversation

@alex-js-ltd
Copy link

@alex-js-ltd alex-js-ltd commented Mar 22, 2026

🎯 Changes

defaultCompare uses === for equality checks which has two edge case failures:

  • NaN === NaN returns false, causing spurious re-renders when state holds NaN
  • +0 === -0 returns true, swallowing a legitimate state update

🔧 Fix

Replace === with Object.is, which handles both cases correctly and aligns
with how React handles equality internally in useState, useMemo and useEffect.

✅ 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

  • Bug Fixes
    • Fixed store comparison in the React integration to correctly handle edge cases like NaN and -0, ensuring accurate component updates without changing public APIs or hook signatures.
  • Documentation
    • Updated a source reference in the store hook docs for accuracy.
  • Chores
    • Added a patch release note entry and updated repository workflow permissions.

@coderabbitai
Copy link

coderabbitai bot commented Mar 22, 2026

📝 Walkthrough

Walkthrough

A patch updates defaultCompare in useStore to use Object.is(a, b) instead of a === b, fixing NaN and -0 edge-case comparisons. A changeset entry for @tanstack/react-store documents this bugfix. The PR also updates a docs source line reference and adds issues: write to the PR workflow permissions.

Changes

Cohort / File(s) Summary
Changesets
./changeset/chatty-humans-unite.md
Adds a patch release entry documenting the defaultCompare bugfix for the React integration.
useStore Implementation
packages/react-store/src/useStore.ts
Replaces a === b with Object.is(a, b) for defaultCompare, correcting NaN and -0 comparison semantics.
Docs
docs/framework/react/reference/functions/useStore.md
Updates the "Defined in" source line reference for useStore from useStore.ts:13 to useStore.ts:14 (documentation-only).
CI Workflow
.github/workflows/pr.yml
Adds issues: write to the workflow-level permissions block alongside existing permissions.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 I hopped through props both near and far,
Found zeros twinned and a NaN bizarre,
Object.is() leapt in to set things right,
Now comparisons sparkle, tidy and bright,
A tiny patch — a rabbit's delight.

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: replacing === with Object.is in the defaultCompare function, with a fix-type prefix indicating a bug fix.
Description check ✅ Passed The description includes all required sections from the template: detailed explanation of changes with rationale, completed checklist items, and release impact confirmation with changeset generation.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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 and usage tips.

@nx-cloud
Copy link

nx-cloud bot commented Mar 25, 2026

View your CI Pipeline Execution ↗ for commit bded194

Command Status Duration Result
nx affected --targets=test:sherif,test:knip,tes... ✅ Succeeded 24s View ↗
nx run-many --target=build --exclude=examples/** ✅ Succeeded <1s View ↗

☁️ Nx Cloud last updated this comment at 2026-03-25 17:27:33 UTC

@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 25, 2026

@tanstack/angular-store

npm i https://pkg.pr.new/@tanstack/angular-store@298

@tanstack/preact-store

npm i https://pkg.pr.new/@tanstack/preact-store@298

@tanstack/react-store

npm i https://pkg.pr.new/@tanstack/react-store@298

@tanstack/solid-store

npm i https://pkg.pr.new/@tanstack/solid-store@298

@tanstack/store

npm i https://pkg.pr.new/@tanstack/store@298

@tanstack/svelte-store

npm i https://pkg.pr.new/@tanstack/svelte-store@298

@tanstack/vue-store

npm i https://pkg.pr.new/@tanstack/vue-store@298

commit: bded194

Copy link

@coderabbitai coderabbitai bot left a comment

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 the current code and only fix it if needed.

Inline comments:
In @.github/workflows/pr.yml:
- Around line 13-16: Remove the workflow-wide "issues: write" entry from the
permissions block (the permissions key containing "contents: read",
"pull-requests: write", and "issues: write") so only minimal privileges remain
(keep "contents: read" and "pull-requests: write"); if a future action actually
requires issue write access, grant "issues: write" at the specific job or step
scope instead of workflow-wide to minimize privileges.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 51897fdf-6cd3-452b-9e03-7b197ae3c829

📥 Commits

Reviewing files that changed from the base of the PR and between bded194 and 10ccf35.

📒 Files selected for processing (1)
  • .github/workflows/pr.yml

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.

2 participants