Skip to content

fix(react-query): keep unsubscribed useQueries idle - #11130

Open
ShiroKSH wants to merge 1 commit into
TanStack:mainfrom
ShiroKSH:fix/react-usequeries-unsubscribed
Open

fix(react-query): keep unsubscribed useQueries idle#11130
ShiroKSH wants to merge 1 commit into
TanStack:mainfrom
ShiroKSH:fix/react-usequeries-unsubscribed

Conversation

@ShiroKSH

@ShiroKSH ShiroKSH commented Jul 29, 2026

Copy link
Copy Markdown

Summary

  • Keep useQueries results aligned with the cache when subscribed: false.
  • Add a regression test for the initial unsubscribed render.
  • Add a patch changeset for @tanstack/react-query.

Root cause

useQueries stopped subscriptions for subscribed: false, but still assigned _optimisticResults: 'optimistic' to every child observer. An unmounted observer then synthesized isFetching: true and fetchStatus: 'fetching' even though it did not run the query function and the cache remained idle.

This completes the useQueries portion of the fix proposed in #10739. PR #10759 corrected useBaseQuery, but did not change useQueries.

Validation

  • vitest src/__tests__/useQueries.test.tsx — 23 passing tests, including the new regression.
  • test:types:tscurrent
  • targeted ESLint and Prettier checks
  • Confirmed red-to-green: the new test fails on the pre-fix implementation with isFetching: true / fetchStatus: fetching.

Summary by CodeRabbit

  • Bug Fixes

    • Fixed useQueries so unsubscribed queries no longer display optimistic fetching states.
    • Unsubscribed queries now correctly remain idle and avoid initiating query functions.
  • Tests

    • Added coverage verifying fetching status, query execution, and observer behavior for unsubscribed queries.
  • Release

    • Included a patch release update for @tanstack/react-query.

@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: d0693874-131d-41f9-b4f2-8b024b11e279

📥 Commits

Reviewing files that changed from the base of the PR and between 9d24c45 and 700d854.

📒 Files selected for processing (3)
  • .changeset/tidy-pandas-wait.md
  • packages/react-query/src/__tests__/useQueries.test.tsx
  • packages/react-query/src/useQueries.ts

📝 Walkthrough

Walkthrough

useQueries now avoids optimistic fetching states when subscribed: false, while preserving observer gating. A regression test verifies no query execution, no cache observers, and idle fetching state. A patch changeset documents the fix.

Changes

useQueries subscription behavior

Layer / File(s) Summary
Align optimistic results with subscription state
packages/react-query/src/useQueries.ts, packages/react-query/src/__tests__/useQueries.test.tsx, .changeset/tidy-pandas-wait.md
useQueries derives a shared subscription flag for optimistic result configuration and observer subscription gating. Tests verify unsubscribed queries remain idle without observers or query execution, and a patch release note documents the fix.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: sukvvon

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: keeping unsubscribed useQueries idle.
Description check ✅ Passed It covers the change, root cause, and validation; only the template's Checklist and Release Impact headings are missing.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ 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.

@nx-cloud

nx-cloud Bot commented Jul 30, 2026

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit 700d854

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

☁️ Nx Cloud last updated this comment at 2026-07-30 02:30:08 UTC

@pkg-pr-new

pkg-pr-new Bot commented Jul 30, 2026

Copy link
Copy Markdown
More templates

@tanstack/angular-query-experimental

npm i https://pkg.pr.new/@tanstack/angular-query-experimental@11130

@tanstack/eslint-plugin-query

npm i https://pkg.pr.new/@tanstack/eslint-plugin-query@11130

@tanstack/lit-query

npm i https://pkg.pr.new/@tanstack/lit-query@11130

@tanstack/preact-query

npm i https://pkg.pr.new/@tanstack/preact-query@11130

@tanstack/preact-query-devtools

npm i https://pkg.pr.new/@tanstack/preact-query-devtools@11130

@tanstack/preact-query-persist-client

npm i https://pkg.pr.new/@tanstack/preact-query-persist-client@11130

@tanstack/query-async-storage-persister

npm i https://pkg.pr.new/@tanstack/query-async-storage-persister@11130

@tanstack/query-broadcast-client-experimental

npm i https://pkg.pr.new/@tanstack/query-broadcast-client-experimental@11130

@tanstack/query-core

npm i https://pkg.pr.new/@tanstack/query-core@11130

@tanstack/query-devtools

npm i https://pkg.pr.new/@tanstack/query-devtools@11130

@tanstack/query-persist-client-core

npm i https://pkg.pr.new/@tanstack/query-persist-client-core@11130

@tanstack/query-sync-storage-persister

npm i https://pkg.pr.new/@tanstack/query-sync-storage-persister@11130

@tanstack/react-query

npm i https://pkg.pr.new/@tanstack/react-query@11130

@tanstack/react-query-devtools

npm i https://pkg.pr.new/@tanstack/react-query-devtools@11130

@tanstack/react-query-next-experimental

npm i https://pkg.pr.new/@tanstack/react-query-next-experimental@11130

@tanstack/react-query-persist-client

npm i https://pkg.pr.new/@tanstack/react-query-persist-client@11130

@tanstack/solid-query

npm i https://pkg.pr.new/@tanstack/solid-query@11130

@tanstack/solid-query-devtools

npm i https://pkg.pr.new/@tanstack/solid-query-devtools@11130

@tanstack/solid-query-persist-client

npm i https://pkg.pr.new/@tanstack/solid-query-persist-client@11130

@tanstack/svelte-query

npm i https://pkg.pr.new/@tanstack/svelte-query@11130

@tanstack/svelte-query-devtools

npm i https://pkg.pr.new/@tanstack/svelte-query-devtools@11130

@tanstack/svelte-query-persist-client

npm i https://pkg.pr.new/@tanstack/svelte-query-persist-client@11130

@tanstack/vue-query

npm i https://pkg.pr.new/@tanstack/vue-query@11130

@tanstack/vue-query-devtools

npm i https://pkg.pr.new/@tanstack/vue-query-devtools@11130

commit: 700d854

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.

1 participant