fix(react): use Object.is instead of === in defaultCompare by alex-js-ltd · Pull Request #298 · TanStack/store · GitHub
Skip to content

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

Open
alex-js-ltd wants to merge 8 commits into
TanStack:mainfrom
alex-js-ltd:fix/default-compare-object-is
Open

alex-js-ltd wants to merge 8 commits into
TanStack:mainfrom
alex-js-ltd:fix/default-compare-object-is

Conversation

@alex-js-ltd

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

Copy link
Copy Markdown

🎯 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

coderabbitai Bot commented Mar 22, 2026 •

Copy link
Copy Markdown
Contributor

@nx-cloud

nx-cloud Bot commented Mar 25, 2026 •

Copy link
Copy Markdown

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

pkg-pr-new Bot commented Mar 25, 2026 •

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

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

Comment thread .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