Skip to content

Commit a9d2617

Browse files
committed
fix(in-app): stale tickets result
1 parent 32c023a commit a9d2617

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

in-app/v1/src/App/Tickets/New/index.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useMemo } from 'react';
22
import { Link, useLocation, useNavigate } from 'react-router-dom';
33
import { useTranslation } from 'react-i18next';
4-
import { useMutation } from 'react-query';
4+
import { useMutation, useQueryClient } from 'react-query';
55
import { Helmet } from 'react-helmet-async';
66
import { pick, cloneDeep } from 'lodash-es';
77

@@ -180,9 +180,16 @@ export function NewTicket() {
180180
}
181181
}, [categories, category_id]);
182182

183+
const queryClient = useQueryClient();
184+
183185
const { mutateAsync: submit, isLoading: submitting } = useMutation({
184186
mutationFn: createTicket,
185187
onSuccess: (ticketId: string) => {
188+
// In react-query@3, useInfiniteQuery always returns stale data
189+
// Clear tickets query cache manaully to prevent this
190+
const cache = queryClient.getQueryCache();
191+
cache.findAll(['tickets']).forEach((query) => cache.remove(query));
192+
186193
navigate({ pathname: '', search }, { replace: false, state: ticketId });
187194
},
188195
});

0 commit comments

Comments
 (0)