From cfae4aba409db0b1f21924ea001d0455cbfe4a7f Mon Sep 17 00:00:00 2001 From: Wonsuk Choi Date: Sun, 22 Feb 2026 21:55:22 +0900 Subject: [PATCH 1/2] test(react-query/useQuery): add test for not fetching during restoring period when 'isRestoring' is true --- .../src/__tests__/useQuery.test.tsx | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/packages/react-query/src/__tests__/useQuery.test.tsx b/packages/react-query/src/__tests__/useQuery.test.tsx index 3c7f7562a8f..46b2a9654bd 100644 --- a/packages/react-query/src/__tests__/useQuery.test.tsx +++ b/packages/react-query/src/__tests__/useQuery.test.tsx @@ -8,6 +8,7 @@ import { sleep, } from '@tanstack/query-test-utils' import { + IsRestoringProvider, QueryCache, QueryClient, dehydrate, @@ -6950,4 +6951,47 @@ describe('useQuery', () => { expect(fetchCount).toBe(initialFetchCount + 1) expect(queryFn).toHaveBeenCalledTimes(2) }) + + it('should not fetch for the duration of the restoring period when isRestoring is true', async () => { + const key = queryKey() + const queryFn = vi.fn().mockImplementation(() => + sleep(10).then(() => 'data'), + ) + + function Page() { + const result = useQuery({ + queryKey: key, + queryFn, + }) + + return ( +
+
{result.status}
+
{result.fetchStatus}
+
{result.data ?? 'undefined'}
+
+ ) + } + + const rendered = renderWithClient( + queryClient, + + + , + ) + + await vi.advanceTimersByTimeAsync(0) + + expect(rendered.getByTestId('status')).toHaveTextContent('pending') + expect(rendered.getByTestId('fetchStatus')).toHaveTextContent('idle') + expect(rendered.getByTestId('data')).toHaveTextContent('undefined') + expect(queryFn).toHaveBeenCalledTimes(0) + + await vi.advanceTimersByTimeAsync(11) + + expect(rendered.getByTestId('status')).toHaveTextContent('pending') + expect(rendered.getByTestId('fetchStatus')).toHaveTextContent('idle') + expect(rendered.getByTestId('data')).toHaveTextContent('undefined') + expect(queryFn).toHaveBeenCalledTimes(0) + }) }) From 78ab024fa6200a29f3cd16dc21d3430c477c4b9b Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Sun, 22 Feb 2026 12:57:09 +0000 Subject: [PATCH 2/2] ci: apply automated fixes --- packages/react-query/src/__tests__/useQuery.test.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/react-query/src/__tests__/useQuery.test.tsx b/packages/react-query/src/__tests__/useQuery.test.tsx index 46b2a9654bd..99f2f39d036 100644 --- a/packages/react-query/src/__tests__/useQuery.test.tsx +++ b/packages/react-query/src/__tests__/useQuery.test.tsx @@ -6954,9 +6954,9 @@ describe('useQuery', () => { it('should not fetch for the duration of the restoring period when isRestoring is true', async () => { const key = queryKey() - const queryFn = vi.fn().mockImplementation(() => - sleep(10).then(() => 'data'), - ) + const queryFn = vi + .fn() + .mockImplementation(() => sleep(10).then(() => 'data')) function Page() { const result = useQuery({