fix: flatten queryKey to primitives for reliable TanStack Query key comparison
Some checks failed
CI / ci (pull_request) Failing after 3m12s
CI / ci (push) Failing after 2m53s

This commit is contained in:
Sergey Krylov 2026-06-22 19:56:53 +03:00
parent 0ddd9b5f80
commit 6f4b46c964
2 changed files with 7 additions and 3 deletions

View File

@ -80,7 +80,10 @@ describe('useBrokerEvents', () => {
it('reuses cache when query key matches', async () => { it('reuses cache when query key matches', async () => {
const queryClient = new QueryClient({ defaultOptions: { queries: { retry: false } } }); const queryClient = new QueryClient({ defaultOptions: { queries: { retry: false } } });
queryClient.setQueryData(['broker', 'events', 'acc-1', query], mockEventsData); queryClient.setQueryData(
['broker', 'events', 'acc-1', '2026-06-22', '2026-06-29'],
mockEventsData,
);
const { result } = renderHook(() => useBrokerEvents('acc-1', query), { const { result } = renderHook(() => useBrokerEvents('acc-1', query), {
wrapper: createWrapper(queryClient), wrapper: createWrapper(queryClient),

View File

@ -3,10 +3,11 @@ import type { BrokerEventsData } from '@/shared/api/responses';
import { getBrokerEvents, type BrokerEventsQuery } from '../api/brokerEventApi'; import { getBrokerEvents, type BrokerEventsQuery } from '../api/brokerEventApi';
export function useBrokerEvents(accountId: string | undefined, query: BrokerEventsQuery) { export function useBrokerEvents(accountId: string | undefined, query: BrokerEventsQuery) {
const { from, to } = query;
return useQuery<BrokerEventsData>({ return useQuery<BrokerEventsData>({
queryKey: ['broker', 'events', accountId, query], queryKey: ['broker', 'events', accountId, from, to],
enabled: Boolean(accountId), enabled: Boolean(accountId),
queryFn: async () => (await getBrokerEvents(accountId!, query)).data, queryFn: async () => (await getBrokerEvents(accountId!, { from, to })).data,
staleTime: 300_000, staleTime: 300_000,
retry: 2, retry: 2,
refetchOnWindowFocus: false, refetchOnWindowFocus: false,