Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: add error message for skipToken in useSuspenseQueries and useSuspenseInfiniteQuery #7797

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion packages/react-query/src/useSuspenseInfiniteQuery.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use client'
import { InfiniteQueryObserver } from '@tanstack/query-core'
import { InfiniteQueryObserver, skipToken } from '@tanstack/query-core'
import { useBaseQuery } from './useBaseQuery'
import { defaultThrowOnError } from './suspense'
import type {
Expand Down Expand Up @@ -32,6 +32,12 @@
>,
queryClient?: QueryClient,
): UseSuspenseInfiniteQueryResult<TData, TError> {
if (process.env.NODE_ENV !== 'production') {
if (options.queryFn === skipToken) {
console.error('skipToken is not allowed for useSuspenseInfiniteQuery')

Check warning on line 37 in packages/react-query/src/useSuspenseInfiniteQuery.ts

View check run for this annotation

Codecov / codecov/patch

packages/react-query/src/useSuspenseInfiniteQuery.ts#L37

Added line #L37 was not covered by tests
}
}

return useBaseQuery(
{
...options,
Expand Down
35 changes: 22 additions & 13 deletions packages/react-query/src/useSuspenseQueries.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
'use client'
import {
type DefaultError,
type QueryClient,
type QueryFunction,
type ThrowOnError,
skipToken,
} from '@tanstack/query-core'
import { useQueries } from './useQueries'
import { defaultThrowOnError } from './suspense'
import type { UseSuspenseQueryOptions, UseSuspenseQueryResult } from './types'
import type {
DefaultError,
QueryClient,
QueryFunction,
ThrowOnError,
} from '@tanstack/query-core'

// Avoid TS depth-limit error in case of large array literal
type MAXIMUM_DEPTH = 20
Expand Down Expand Up @@ -190,13 +191,21 @@
return useQueries(
{
...options,
queries: options.queries.map((query) => ({
...query,
suspense: true,
throwOnError: defaultThrowOnError,
enabled: true,
placeholderData: undefined,
})),
queries: options.queries.map((query) => {
if (process.env.NODE_ENV !== 'production') {
if (query.queryFn === skipToken) {
console.error('skipToken is not allowed for useSuspenseQueries')

Check warning on line 197 in packages/react-query/src/useSuspenseQueries.ts

View check run for this annotation

Codecov / codecov/patch

packages/react-query/src/useSuspenseQueries.ts#L197

Added line #L197 was not covered by tests
}
}

return {
...query,
suspense: true,
throwOnError: defaultThrowOnError,
enabled: true,
placeholderData: undefined,
}
}),
} as any,
queryClient,
)
Expand Down
Loading