Skip to content

docs(tanstack-react-query): handles work with useQuery too, and every reader needs a loading state - #7842

Merged
KATT merged 3 commits into
mainfrom
cursor/handles-loading-states-0ee9
Nov 3, 2026
Merged

KATT merged 3 commits into
mainfrom
cursor/handles-loading-states-0ee9

Conversation

@KATT

@KATT KATT commented Nov 2, 2026 •

Copy link
Copy Markdown
Member

Why

  • The handles docs implied you need useSuspenseQuery and a Suspense boundary to read a handle. You don't: useQuery works with every method.
  • They also said a reader after unstable_$ensure needs no Suspense boundary. It renders at once, but the cache can lose the data later, and then the reader loads it again.

What

  • handles.md:
    • New Reading with useQuery section, with a sample that switches on postQuery.status.
    • New When the cache loses the data section. It covers resetQueries, removeQueries and clear(), gcTime, and invalidateQueries, and says to give every reader a loading state.
    • unstable_$prefetch and unstable_$ensure bullets, the "Which to use" table, the in-render notes and the Next.js unstable_$ensure notes no longer say a Suspense boundary is needed or not needed.
  • usage.md and tanstack-start.md: the same fix in their short handle notes.

I checked each claim against TanStack Query 5 with a scratch test, reading a handle from unstable_$ensure:

Action useQuery useSuspenseQuery
resetQueries() At once: pending, no data, refetch At once: suspends, shows fallback
removeQueries(), clear() Keeps old data until its next render, then pending Keeps old data until its next render, then suspends
invalidateQueries() Keeps data, refetches in the background Keeps data, refetches in the background

Links

Open in Web Open in Cursor 

Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

Summary by CodeRabbit

  • Documentation
    • Clarified when query readers may show a loading state or suspend, including when cached data is removed, reset, invalidated, or lost to garbage collection.
    • Explained that stale cached data can remain visible during a background refetch.
    • Updated guidance on loading behavior for prefetched and ensured handles, including using useQuery’s pending status.
    • Revised Next.js and waiting-loader examples to account for data that may no longer be in the cache.

… reader needs a loading state

Co-authored-by: alexander <[email protected]>
@KATT
KATT requested a review from a team as a code owner November 2, 2026 23:49
@vercel

vercel Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

7 Skipped Deployments
Project Deployment Actions Updated
examples-next-minimal-starter Skipped Skipped Nov 3, 2026 12:25am UTC
examples-todomvc Skipped Skipped Nov 3, 2026 12:25am UTC
next-prisma-starter Skipped Skipped Nov 3, 2026 12:25am UTC
next-prisma-websockets-starter Skipped Skipped Nov 3, 2026 12:25am UTC
tanstack-start-sse-chat Skipped Skipped Nov 3, 2026 12:25am UTC
trpc-next-app-dir Skipped Skipped Nov 3, 2026 12:25am UTC
www Skipped Skipped Nov 3, 2026 12:25am UTC

Request Review

@coderabbitai

coderabbitai Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between f45e7fd and d77734f.

Files selected for processing: 1
  • www/v11/docs/client/tanstack-react-query/handles.md
Files skipped from review as they are similar to previous changes: 1
  • www/v11/docs/client/tanstack-react-query/handles.md

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.

Walkthrough

The documentation updates explain loading states for useQuery and useSuspenseQuery, first-render behavior after prefetch, ensure, or fetch, and reader behavior after cache changes. They also revise in-render and framework-specific guidance.

Changes: Query handle documentation

Layer / File(s) Summary
Initial reader loading states
www/v11/docs/client/tanstack-react-query/handles.md, www/v11/docs/client/tanstack-react-query/usage.md
The docs distinguish prefetch loading from the cached first render after ensure or fetch. They describe useSuspenseQuery fallbacks and useQuery pending states.
Reader states and cache loss
www/v11/docs/client/tanstack-react-query/handles.md
The docs describe useQuery pending, error, and success states. They cover data removal, reset, garbage collection, and background refetch after invalidation.
In-render and framework guidance
www/v11/docs/client/tanstack-react-query/handles.md, www/v11/docs/client/tanstack-react-query/tanstack-start.md
The docs describe reader choices during rendering and explain that readers can suspend if cached data is later lost, including in Next.js and TanStack Start examples.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Change: Other

Possibly related PRs

  • trpc/trpc#7817: Introduced the query-handle documentation in the same pages.
  • trpc/trpc#7822: Changed handle data behavior and reader fetching after cache loss.
  • trpc/trpc#7838: Documents the choice between useQuery and useSuspenseQuery for unawaited work.

Suggested reviewers: trpc-bot

Merge Risk: Minimal · up to e6111

Merge Risk: ⚪ Minimal · up to e6111

The loading-state guidance has no identified issue requiring a fix before merge.

Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely summarizes the main documentation changes: handle support with useQuery and loading-state requirements for readers.
Docstring Coverage Passed No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
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.
Full details: Docstring Coverage

Explanation

No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 0 functions across 0 files. (1 skipped: 1 unsupported.)

Finishing Touches
Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

CodeRabbit Verify

  • Run CodeRabbit Verify to test the changes in this pull request.

@pkg-pr-new

pkg-pr-new Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@trpc/client

npm i https://pkg.pr.new/@trpc/client@7842

@trpc/next

npm i https://pkg.pr.new/@trpc/next@7842

@trpc/openapi

npm i https://pkg.pr.new/@trpc/openapi@7842

@trpc/react-query

npm i https://pkg.pr.new/@trpc/react-query@7842

@trpc/server

npm i https://pkg.pr.new/@trpc/server@7842

@trpc/tanstack-react-query

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

@trpc/upgrade

npm i https://pkg.pr.new/@trpc/upgrade@7842

commit: e611132

@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.

  • Fix comments: Fix CodeRabbit comments on this PR

@vercel
vercel Bot temporarily deployed to Preview – next-prisma-starter November 2, 2026 23:58 Inactive
@vercel
vercel Bot temporarily deployed to Preview – examples-next-minimal-starter November 2, 2026 23:58 Inactive
@vercel
vercel Bot temporarily deployed to Preview – trpc-next-app-dir November 2, 2026 23:58 Inactive
@vercel
vercel Bot temporarily deployed to Preview – examples-todomvc November 2, 2026 23:58 Inactive
@vercel
vercel Bot temporarily deployed to Preview – examples-todomvc November 3, 2026 00:25 Inactive
@vercel
vercel Bot temporarily deployed to Preview – www November 3, 2026 00:25 Inactive
@vercel
vercel Bot temporarily deployed to Preview – examples-next-minimal-starter November 3, 2026 00:25 Inactive
@vercel
vercel Bot temporarily deployed to Preview – next-prisma-starter November 3, 2026 00:25 Inactive
@vercel
vercel Bot temporarily deployed to Preview – trpc-next-app-dir November 3, 2026 00:25 Inactive

@trpc-bot trpc-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI is green and all CodeRabbit threads are resolved.

@KATT
KATT added this pull request to the merge queue Nov 3, 2026
Merged via the queue into main with commit 2c599c3 Nov 3, 2026
52 checks passed
@KATT
KATT deleted the cursor/handles-loading-states-0ee9 branch November 3, 2026 00:59
@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

This pull request has been locked because we are very unlikely to see comments on closed issues. If you think, this PR is still necessary, create a new one with the same branch. Thank you.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Nov 4, 2026

This branch was previously deployed

5 inactive deployments
Preview – www — e611132d Deployed Nov 3, 2026 by vercel[bot]
Preview – examples-next-minimal-starter — e611132d Deployed Nov 3, 2026 by vercel[bot]
Preview – next-prisma-starter — e611132d Deployed Nov 3, 2026 by vercel[bot]
Preview – trpc-next-app-dir — e611132d Deployed Nov 3, 2026 by vercel[bot]
Preview – examples-todomvc — e611132d Deployed Nov 3, 2026 by vercel[bot]
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants