fix(react): use Object.is instead of === in defaultCompare #298
main fromrefs/pull/298/head·opened 🎯 Changes#
defaultCompare uses === for equality checks which has two edge case failures:
NaN === NaNreturnsfalse, causing spurious re-renders when state holdsNaN+0 === -0returnstrue, 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
View your CI Pipeline Execution ↗ for commit bded194ece0ec215ad7a2473930933bbb29db21a
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:33UTC@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@298commit:
bded194Actionable 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
.github/workflows/pr.yml lines 13 to 16Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -13,3 +13,4 @@1313 permissions:1414 contents: read1515 pull-requests: write16+ issues: write⚠️ Potential issue | 🟠 Major
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash # Verify whether this repository actually performs issue-write operations in CI/workflows. # Expected: no concrete issue-write callsites unless a reusable action truly needs this scope. rg -n -C3 'issues:\s*write|gh issue|/issues\b|octokit\.rest\.issues|createIssue|updateIssue|createComment' .github/workflows rg -n -C3 'gh issue|octokit\.rest\.issues|createIssue|updateIssue|createComment'Repository: TanStack/store
Length of output: 337
🏁 Script executed:
cat -n .github/workflows/pr.ymlRepository: TanStack/store
Length of output: 2466
🏁 Script executed:
# Check if there's any documentation or README that mentions required permissions find . -type f -name "*.md" | xargs grep -l "issues.*write\|permission" 2>/dev/null | head -20Repository: TanStack/store
Length of output: 40
🌐 Web query:
TanStack/config changeset-preview action issues write permission requirements💡 Result:
The TanStack/config repository provides reusable GitHub Actions workflows, including a "changeset-preview" action (referenced as TanStack/config/.github/changeset-preview@main) used across TanStack projects like TanStack/query and TanStack/router for previewing changeset version bumps in PRs. This action is invoked in PR workflows (e.g., .github/workflows/pr.yml) with jobs like "version-preview" that perform checkout, setup tools, and run the changeset preview step. No explicit write permission requirements are stated in the TanStack/config workflows or docs. The action appears read-only: it checks out code, sets up the environment (pnpm/Node), and runs changeset preview to analyze .changeset files and post a comment with version preview info (e.g., "No changeset entries found. Merging this PR will not cause a version bump."). General GitHub Actions best practices and changesets/action documentation apply: - Repository settings: Enable "Read and write permissions" (Settings > Actions > General > Workflow permissions) if default read-only permissions block operations. - Workflow YAML: Add permissions: { contents: read, pull-requests: write } at job/workflow level if the preview posts PR comments (common for preview actions). - For GITHUB_TOKEN: Default token has read permissions; write requires explicit settings or PAT for actions creating/updating PRs/comments. If issues arise (e.g., "GitHub Actions is not permitted to create or approve pull requests"), check: 1. Repo workflow permissions set to read/write. 2. No pull_request_target trigger without permissions: { contents: read }. 3. Use ${{ github.token }} or repo PAT with repo scope. Sources confirm usage in recent (2026) PRs without permission complaints, suggesting minimal/read-only needs. For full write access (e.g., if action evolved), align with changesets/action: permissions: { contents: write, pull-requests: write }. Direct repo workflows (.github/pr.yml etc.) show no permissions block, implying reliance on repo defaults.
Citations:
- 1: https://github.com/TanStack/query/pull/10277
- 2: https://github.com/TanStack/router/pull/6944
- 3: https://github.com/TanStack/config/blob/main/.github/workflows/pr.yml
- 4: https://github.com/TanStack/config
- 5: https://github.com/TanStack/query/pull/9502
- 6: https://github.com/TanStack/router/pull/6837
- 7: https://deepwiki.com/TanStack/config/6.1-github-workflows
- 8: https://github.com/TanStack/router/pull/6952
- 9: https://www.berkeleycitizensaction.org
- 10: https://www.stagehand-framework.github.io
- 11: https://www.globalactionmag.com
- 12: https://www.with-permission.com
🏁 Script executed:
# Double-check for any issue-related operations in the entire .github directory rg -i "issue" .github/workflows/ --type yaml -C2Repository: TanStack/store
Length of output: 245
Remove workflow-wide
issues: writeunless an action explicitly requires it.Line 16expands token privileges unnecessarily. This workflow performs no issue mutations—only PR checkout, builds, and preview comments (viaTanStack/config/.github/changeset-preview), which require onlypull-requests: write. Keep permissions minimal to reduce blast radius on same-repo PR runs.Suggested change
permissions: contents: read pull-requests: write - issues: write📝 Committable suggestion
‼️ IMPORTANT Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
Suggested change13-permissions:14- contents: read15- pull-requests: write16- issues: write13+permissions:14+ contents: read15+ pull-requests: write🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In @.github/workflows/pr.yml around lines 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.✅ Confirmed as addressed by @alex-js-ltd
issues: writeis required here.The changeset preview step posts via the Issues API, and removing it caused a 403 ("Resource not accessible by integration"), so this permission is needed. Happy to adjust if there's a better approach.
@alex-js-ltd, thanks for the clarification and for testing it directly — that's the definitive proof. You're right: GitHub routes PR conversation/timeline comments through the Issues API (/repos/{owner}/{repo}/issues/{issue_number}/comments), soissues: writeis indeed required for thechangeset-previewstep to post its summary comment on PRs. Thepull-requests: writepermission only covers inline review comments, not the top-level conversation comments. The permission is justified here.
✏️ Learnings added
Learnt from: alex-js-ltd Repo: TanStack/store PR: 298 File: .github/workflows/pr.yml:13-16 Timestamp: 2026-03-26T10:25:46.608Z Learning: In the TanStack/store repository's `.github/workflows/pr.yml`, the `issues: write` permission is required at the workflow level because the `TanStack/config/.github/changeset-previewmain` action posts changeset preview comments via the GitHub Issues API (PR conversation comments use the Issues API endpoint). Removing this permission causes a 403 "Resource not accessible by integration" error. `pull-requests: write` alone is insufficient for posting top-level PR conversation comments.Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.
Sign in to join this conversation.
📝 Walkthrough
Walkthrough#
A patch updates
defaultCompareinuseStoreto useObject.is(a, b)instead ofa === b, fixingNaNand-0edge-case comparisons. A changeset entry for@tanstack/react-storedocuments this bugfix. The PR also updates a docs source line reference and addsissues: writeto the PR workflow permissions.Changes#
./changeset/chatty-humans-unite.mddefaultComparebugfix for the React integration.packages/react-store/src/useStore.tsa === bwithObject.is(a, b)fordefaultCompare, correctingNaNand-0comparison semantics.docs/framework/react/reference/functions/useStore.mduseStorefromuseStore.ts:13touseStore.ts:14(documentation-only)..github/workflows/pr.ymlissues: writeto the workflow-levelpermissionsblock alongside existing permissions.Estimated code review effort#
🎯 2 (Simple) | ⏱️ ~10 minutes
Poem#
🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)#
✅ Passed checks (2 passed)
✨ 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