Skip to content

feat(react-query): backport v5 apis about infinite query - #9334

Merged
manudeli merged 2 commits into
TanStack:v4from
manudeli:react-query/backport-infinite-query
Sep 9, 2025
Merged

feat(react-query): backport v5 apis about infinite query#9334
manudeli merged 2 commits into
TanStack:v4from
manudeli:react-query/backport-infinite-query

Conversation

@manudeli

@manudelimanudeli commented Jun 29, 2025

Copy link
Copy Markdown
Collaborator

New Features and Utilities:

  • Added infiniteQueryOptions
  • Added useSuspenseInfiniteQuery
  • Added type DefinedInitialDataInfiniteOptions, type UndefinedInitialDataInfiniteOptions
  • Added function overload for useInfiniteQuery to return DefinedUseInfiniteQueryResult when using infiniteData

Deprecations:

  • Marked several overloads of useInfiniteQuery as deprecated, with a note that they will be removed in the next major version. (packages/react-query/src/useInfiniteQuery.ts)

@manudelimanudeli self-assigned this Jun 29, 2025
@nx-cloud

nx-cloudBot commented Jun 29, 2025

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit 32d3516

CommandStatusDurationResult
nx affected --targets=test:lib,test:types,test:...✅ Succeeded20sView ↗
nx affected --targets=test:lib --base=508d5a066...✅ Succeeded<1sView ↗

☁️ Nx Cloud last updated this comment at 2025-09-09 07:09:48 UTC

This comment was marked as outdated.

@manudeli
manudeli requested a review from CopilotJuly 16, 2025 09:25

This comment was marked as outdated.

@manudeli
manudeli requested a review from CopilotJuly 16, 2025 09:35

This comment was marked as outdated.

@manudeli
manudeliforce-pushed the react-query/backport-infinite-query branch from 91170ba to 89fb2fbCompareJuly 29, 2025 15:33
@manudeli
manudeli requested a review from CopilotJuly 29, 2025 15:33

CopilotAI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull Request Overview

This PR backports infinite query APIs from React Query v5 to provide enhanced infinite query functionality and improve API consistency.

  • Added useSuspenseInfiniteQuery hook for suspense-based infinite queries with automatic error boundaries
  • Added infiniteQueryOptions function for creating type-safe infinite query configurations
  • Deprecated multiple function overloads in useQuery and useInfiniteQuery with improved deprecation messages

Reviewed Changes

Copilot reviewed 14 out of 15 changed files in this pull request and generated 2 comments.

Show a summary per file
FileDescription
packages/react-query/src/useSuspenseInfiniteQuery.tsNew suspense-based infinite query hook implementation
packages/react-query/src/infiniteQueryOptions.tsNew infinite query options factory function with type definitions
packages/react-query/src/types.tsAdded new result types for suspense and defined infinite queries
packages/react-query/src/useQuery.tsEnhanced deprecation messages for function overloads
packages/react-query/src/useInfiniteQuery.tsAdded new overload and enhanced deprecation messages
packages/react-query/src/queryOptions.tsUpdated to omit prohibited v5 keys from options
packages/react-query/src/index.tsExported new functions and types
packages/react-query/src/tests/*Comprehensive type and unit tests for new functionality
packages/query-core/src/types.tsCleaned up deprecated comment formatting
packages/query-core/src/queryClient.tsCleaned up deprecated comment formatting
packages/query-core/src/queryCache.tsCleaned up deprecated comment formatting
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported
Comments suppressed due to low confidence (1)

packages/react-query/src/infiniteQueryOptions.ts:22

  • The type name ProhibitedInfiniteQueryOptionsKeyInV5 is inconsistent with the similar type in queryOptions.ts which is named ProhibitedQueryOptionsKeyInV5. Consider renaming to ProhibitedQueryOptionsKeyInV5 for consistency.
 'useErrorBoundary' | 'suspense'

DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>,
OmitKeyof<
DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>,
ProhibitedQueryOptionsKeyInV5

CopilotAIJul 29, 2025

Copy link

Choose a reason for hiding this comment

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

The type ProhibitedQueryOptionsKeyInV5 is referenced but not defined in this file. This will cause a TypeScript compilation error.

Copilot uses AI. Check for mistakes.
UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>,
OmitKeyof<
UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>,
ProhibitedQueryOptionsKeyInV5

CopilotAIJul 29, 2025

Copy link

Choose a reason for hiding this comment

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

The type ProhibitedQueryOptionsKeyInV5 is referenced but not defined in this file. This will cause a TypeScript compilation error.

Copilot uses AI. Check for mistakes.
@codesandbox-ci

codesandbox-ciBot commented Jul 29, 2025

Copy link
Copy Markdown

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 32d3516:

SandboxSource
@tanstack/query-example-react-basic-typescriptConfiguration
@tanstack/query-example-solid-basic-typescriptConfiguration
@tanstack/query-example-svelte-basicConfiguration
@tanstack/query-example-vue-basicConfiguration

@manudeli
manudeli marked this pull request as ready for review July 29, 2025 15:46
@manudeli
manudeli requested a review from TkDodoJuly 29, 2025 15:59
@manudeli
manudeliforce-pushed the react-query/backport-infinite-query branch from 15a9bcf to 9aaf337CompareJuly 29, 2025 16:09

@manudelimanudeli left a comment

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

@TkDodo I left comments with my intentions

Comment on lines +19 to +37
export function useInfiniteQuery<
TQueryFnData = unknown,
TError = unknown,
TData = TQueryFnData,
TQueryKey extends QueryKey = QueryKey,
>(
options: UseInfiniteQueryOptions<
TQueryFnData,
TError,
TData,
TQueryFnData,
TQueryKey
> & {
initialData:
| NonUndefinedGuard<InfiniteData<TQueryFnData>>
| (() => NonUndefinedGuard<InfiniteData<TQueryFnData>>)
| undefined
},
): DefinedUseInfiniteQueryResult<TData, TError>

@manudelimanudeliJul 29, 2025

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

Another function overload that returns DefinedUseInfiniteQueryResult is added when using initialData.

@tanstack/react-query v5 also support this

Comment on lines +124 to +135
export type DefinedUseInfiniteQueryResult<
TData = unknown,
TError = unknown,
> = DefinedInfiniteQueryObserverResult<TData, TError>

export type UseSuspenseInfiniteQueryResult<
TData = unknown,
TError = unknown,
> = OmitKeyof<
DefinedInfiniteQueryObserverResult<TData, TError>,
'isPlaceholderData'
>

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

new types

TQueryKey
>,
): UseInfiniteQueryResult<TData, TError>
/** @deprecated This function overload will be removed in the next major version. */

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

Mark some useInfiniteQuery's function overloads as deprecated

@coderabbitai

coderabbitaiBot commented Aug 24, 2025

Copy link
Copy Markdown
Contributor

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Comment @coderabbitai help to get the list of available commands and usage tips.

…ryOptions for enhanced infinite query handling
- Added `useSuspenseInfiniteQuery` hook for improved suspense handling with infinite queries.
- Introduced `infiniteQueryOptions` function to streamline infinite query option management.
- Updated types to include `DefinedInfiniteQueryObserverResult` and related types for better type safety.
- Refactored existing query options to accommodate new infinite query features.
- Added tests for new functionalities to ensure correctness and type safety.
@manudeli
manudeliforce-pushed the react-query/backport-infinite-query branch from 94085b4 to ed2a35bCompareSeptember 9, 2025 07:03
@manudeli
manudeli merged commit 208029e into TanStack:v4Sep 9, 2025
4 checks passed
Sign up for freeto 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.

2 participants

@manudeli