Skip to content
Source
Sign inSign up
TanStack/store

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

Openalex-js-ltd(GitHub profile, opens in a new tab)wants to merge 8 commits intomain fromrefs/pull/298/headopened

🎯 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.
    1. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      📝 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 nameStatusExplanationResolution
      Docstring Coverage⚠️ WarningDocstring 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 nameStatusExplanation
      Title check✅ PassedThe 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✅ PassedThe 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.
    2. nx-cloud[bot](GitHub profile, opens in a new tab)commented

      View your CI Pipeline Execution ↗ for commit bded194ece0ec215ad7a2473930933bbb29db21a

      CommandStatusDurationResult
      nx affected --targets=test:sherif,test:knip,tes...✅ Succeeded24sView ↗
      nx run-many --target=build --exclude=examples/**✅ Succeeded<1sView ↗

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

    3. pkg-pr-new[bot](GitHub profile, opens in a new tab)commented
      @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

    4. 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 bded194ece0ec215ad7a2473930933bbb29db21a and 10ccf354160445673c7d50b60f77fb7a57e7450e.

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

Sign in to join this conversation.