diff --git a/packages/query-core/src/queryClient.ts b/packages/query-core/src/queryClient.ts index 86d551b0f3..a62a6ee9c2 100644 --- a/packages/query-core/src/queryClient.ts +++ b/packages/query-core/src/queryClient.ts @@ -668,10 +668,7 @@ export class QueryClient { defaultedOptions.networkMode = 'offlineFirst' } - if ( - defaultedOptions.enabled !== true && - defaultedOptions.queryFn === skipToken - ) { + if (defaultedOptions.queryFn === skipToken) { defaultedOptions.enabled = false } diff --git a/packages/react-query/src/__tests__/useQuery.test.tsx b/packages/react-query/src/__tests__/useQuery.test.tsx index e336b99815..9f0cbce408 100644 --- a/packages/react-query/src/__tests__/useQuery.test.tsx +++ b/packages/react-query/src/__tests__/useQuery.test.tsx @@ -6422,6 +6422,39 @@ describe('useQuery', () => { await waitFor(() => rendered.getByText('data: data')) }) + it('should allow enabled: true and queryFn: skipToken', async () => { + const consoleMock = vi + .spyOn(console, 'error') + .mockImplementation(() => undefined) + const key = queryKey() + + function App() { + const query = useQuery({ + queryKey: key, + queryFn: skipToken, + enabled: true, + }) + + return ( +