Skip to content

update usePrefetchQuery to use new methods, plus react adaptor tests - #10661

Closed
DogPawHat wants to merge 1 commit into
TanStack:mainfrom
DogPawHat:simplified-query-methods/react
Closed

update usePrefetchQuery to use new methods, plus react adaptor tests#10661
DogPawHat wants to merge 1 commit into
TanStack:mainfrom
DogPawHat:simplified-query-methods/react

Conversation

@DogPawHat

@DogPawHatDogPawHat commented May 8, 2026

Copy link
Copy Markdown
Contributor

🎯 Changes

Updates the react usePrefetchQuery hook to use the new query and infiniteQuery methods. Adds docs and extra tests for the hooks and impertive methods as well.

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested this code locally with pnpm run test:pr.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.

Summary by CodeRabbit

  • New Features

    • Updated usePrefetchQuery and usePrefetchInfiniteQuery to support the latest query execution options.
    • Prefetching now integrates with query execution while preserving background behavior.
  • Bug Fixes

    • Suspended queries now correctly deduplicate in-flight requests, preventing duplicate fetches.
  • Type Improvements

    • Improved TypeScript inference for selected infinite-query results, fetched results, page parameters, and conditional query functions.
    • Clarified that selection transforms apply to hooks, not direct fetch methods.
  • Documentation

    • Added a migration note for the updated prefetch methods.

@coderabbitai

coderabbitaiBot commented May 8, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 62492e27-5d89-4687-834f-8809b433e1af

📥 Commits

Reviewing files that changed from the base of the PR and between dce04b5 and d5ae5bd.

📒 Files selected for processing (9)
  • .changeset/warm-candies-like.md
  • packages/react-query/src/__tests__/infiniteQueryOptions.test-d.tsx
  • packages/react-query/src/__tests__/queryOptions.test-d.tsx
  • packages/react-query/src/__tests__/useInfiniteQuery.test-d.tsx
  • packages/react-query/src/__tests__/usePrefetchQuery.test-d.tsx
  • packages/react-query/src/__tests__/useQuery.promise.test.tsx
  • packages/react-query/src/types.ts
  • packages/react-query/src/usePrefetchInfiniteQuery.tsx
  • packages/react-query/src/usePrefetchQuery.tsx

📝 Walkthrough

Walkthrough

usePrefetchQuery and usePrefetchInfiniteQuery now use query execution methods and their corresponding option types. Type tests cover selection and page parameter inference. A suspense test verifies in-flight query deduplication.

Changes

Query execution and prefetch hooks

Layer / File(s)Summary
Prefetch hook migration
packages/react-query/src/usePrefetchQuery.tsx, packages/react-query/src/usePrefetchInfiniteQuery.tsx, packages/react-query/src/types.ts, .changeset/warm-candies-like.md
Prefetch hooks now call query and infiniteQuery, accept query execution options, and remove UsePrefetchQueryOptions.
Query option type coverage
packages/react-query/src/__tests__/infiniteQueryOptions.test-d.tsx, packages/react-query/src/__tests__/queryOptions.test-d.tsx, packages/react-query/src/__tests__/useInfiniteQuery.test-d.tsx, packages/react-query/src/__tests__/usePrefetchQuery.test-d.tsx
Type tests cover select, fetchQuery, infinite query page parameters, and skipToken.
Suspense query deduplication
packages/react-query/src/__tests__/useQuery.promise.test.tsx
A suspense test verifies that concurrent queryClient.query calls execute the query function once.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
participant SuspenseComponent
participant QueryClient
participant QueryFunction
SuspenseComponent->>QueryClient: Start suspended query
SuspenseComponent->>QueryClient: Call query(options)
QueryClient->>QueryFunction: Reuse in-flight execution
QueryFunction-->>QueryClient: Resolve data
QueryClient-->>SuspenseComponent: Return resolved data
Loading

Possibly related PRs

  • TanStack/query#10658: Introduces the QueryClient.query and infiniteQuery APIs adopted by the prefetch hooks.

Suggested reviewers:sukvvon

✨ 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-cloudBot commented May 8, 2026

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit f14663a

CommandStatusDurationResult
nx run-many --target=build --exclude=examples/*...✅ Succeeded2sView ↗
nx affected --targets=test:sherif,test:knip,tes...✅ Succeeded1m 22sView ↗

☁️ Nx Cloud last updated this comment at 2026-05-10 20:59:30 UTC

@pkg-pr-new

pkg-pr-newBot commented May 8, 2026

Copy link
Copy Markdown
More templates

@tanstack/angular-query-experimental

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

@tanstack/eslint-plugin-query

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

@tanstack/lit-query

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

@tanstack/preact-query

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

@tanstack/preact-query-devtools

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

@tanstack/preact-query-persist-client

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

@tanstack/query-async-storage-persister

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

@tanstack/query-broadcast-client-experimental

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

@tanstack/query-core

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

@tanstack/query-devtools

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

@tanstack/query-persist-client-core

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

@tanstack/query-sync-storage-persister

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

@tanstack/react-query

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

@tanstack/react-query-devtools

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

@tanstack/react-query-next-experimental

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

@tanstack/react-query-persist-client

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

@tanstack/solid-query

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

@tanstack/solid-query-devtools

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

@tanstack/solid-query-persist-client

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

@tanstack/svelte-query

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

@tanstack/svelte-query-devtools

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

@tanstack/svelte-query-persist-client

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

@tanstack/vue-query

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

@tanstack/vue-query-devtools

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

commit: f14663a

@DogPawHat
DogPawHatforce-pushed the simplified-query-methods/react branch 2 times, most recently from 9ea80e3 to cc234f4CompareMay 9, 2026 14:36
@DogPawHat
DogPawHatforce-pushed the simplified-query-methods/react branch 2 times, most recently from c4a4e17 to f14663aCompareMay 10, 2026 20:53
@DogPawHat
DogPawHatforce-pushed the simplified-query-methods/react branch 2 times, most recently from 235c170 to 8c1fe98CompareJune 11, 2026 06:26
@DogPawHat
DogPawHatforce-pushed the simplified-query-methods/react branch 3 times, most recently from 963e00b to 8ff94d3CompareJune 29, 2026 23:24
@DogPawHat
DogPawHatforce-pushed the simplified-query-methods/react branch from 8ff94d3 to b355b48CompareJuly 9, 2026 23:33
@DogPawHat
DogPawHatforce-pushed the simplified-query-methods/react branch from b355b48 to 029bbc5CompareJuly 23, 2026 10:26
@DogPawHat
DogPawHatforce-pushed the simplified-query-methods/react branch from 029bbc5 to da40aadCompareAugust 15, 2026 03:03
@DogPawHatDogPawHat reopened this Aug 15, 2026
@DogPawHat
DogPawHatforce-pushed the simplified-query-methods/react branch 5 times, most recently from 0f9037b to 4c2a8e5CompareAugust 17, 2026 18:47
@DogPawHat
DogPawHatforce-pushed the simplified-query-methods/react branch from 4c2a8e5 to d5ae5bdCompareAugust 17, 2026 19:02
@DogPawHat
DogPawHat marked this pull request as ready for review August 17, 2026 19:43
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@DogPawHat