Skip to content

Commit f1b3d79

Browse files
scttcperclaude
authored andcommitted
fix(ui): Fix "Missing queryFn" error in useAggregatedQueryKeys (#112488)
`useAggregatedQueryKeys` created a `QueryObserver` without a `queryFn` just to listen for when `fetchQuery` resolved so it could clean up inFlight markers. In TanStack Query v5 this throws "Missing queryFn" Replace the observer with `.finally()` on the promise `fetchQuery` already returns - simpler and doesn't need the subscription ref cleanup. fixes JAVASCRIPT-38K4 Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 8001c2f commit f1b3d79

File tree

1 file changed

+11
-23
lines changed

1 file changed

+11
-23
lines changed

static/app/utils/api/useAggregatedQueryKeys.tsx

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@ import type {ApiResult} from 'sentry/api';
44
import {defined} from 'sentry/utils';
55
import {uniq} from 'sentry/utils/array/uniq';
66
import type {ApiQueryKey} from 'sentry/utils/queryClient';
7-
import {fetchDataQuery, QueryObserver, useQueryClient} from 'sentry/utils/queryClient';
7+
import {fetchDataQuery, useQueryClient} from 'sentry/utils/queryClient';
88

99
const BUFFER_WAIT_MS = 20;
1010

11-
type Subscription = () => void;
12-
1311
interface Props<AggregatableQueryKey, Data> {
1412
/**
1513
* The queryKey reducer
@@ -90,14 +88,6 @@ export function useAggregatedQueryKeys<AggregatableQueryKey, Data>({
9088

9189
const key = getQueryKey([]).at(0);
9290

93-
const subscriptions = useRef<Subscription[]>([]);
94-
useEffect(() => {
95-
const subs = subscriptions.current;
96-
return () => {
97-
subs.forEach(unsubscribe => unsubscribe());
98-
};
99-
}, []);
100-
10191
// The query keys that this instance cares about
10292
const prevQueryKeys = useRef<AggregatableQueryKey[]>([]);
10393

@@ -148,19 +138,17 @@ export function useAggregatedQueryKeys<AggregatableQueryKey, Data>({
148138
});
149139

150140
const queryKey = getQueryKey(queuedAggregatableBatch);
151-
queryClient.fetchQuery({
152-
queryKey,
153-
queryFn: fetchDataQuery,
154-
});
155-
156-
const observer = new QueryObserver(queryClient, {queryKey});
157-
const unsubscribe = observer.subscribe(_result => {
158-
queryClient.removeQueries({
159-
queryKey: ['aggregate', cacheKey, key, 'inFlight'],
160-
predicate: isQueryKeyInBatch,
141+
queryClient
142+
.fetchQuery({
143+
queryKey,
144+
queryFn: fetchDataQuery,
145+
})
146+
.finally(() => {
147+
queryClient.removeQueries({
148+
queryKey: ['aggregate', cacheKey, key, 'inFlight'],
149+
predicate: isQueryKeyInBatch,
150+
});
161151
});
162-
});
163-
subscriptions.current.push(unsubscribe);
164152

165153
if (allQueuedQueries.length > queuedQueriesBatch.length) {
166154
fetchData();

0 commit comments

Comments
 (0)