diff --git a/app/api/hooks.ts b/app/api/hooks.ts index 70c70a7778..2fb25c6faf 100644 --- a/app/api/hooks.ts +++ b/app/api/hooks.ts @@ -12,7 +12,6 @@ import { useQueryClient, type DefaultError, type FetchQueryOptions, - type InvalidateQueryFilters, type QueryClient, type UndefinedInitialDataOptions, type UseMutationOptions, @@ -241,16 +240,12 @@ export const getUseApiMutation = export const wrapQueryClient = (api: A, queryClient: QueryClient) => ({ /** - * Note that we only take a single argument, `method`, rather than allowing - * the full query key `[query, params]` to be specified. This is to avoid - * accidentally overspecifying and therefore failing to match the desired - * query. The params argument can be added back in if we ever have a use case - * for it. - * - * Passing no arguments will invalidate all queries. + * Even though it's possible to specify params, prefer invalidating by method + * alone to avoid accidentally overspecifying and therefore failing to match + * the desired query. */ - invalidateQueries: (method?: M, filters?: InvalidateQueryFilters) => - queryClient.invalidateQueries(method ? { queryKey: [method], ...filters } : undefined), + invalidateQueries: (method: M, params?: Params) => + queryClient.invalidateQueries({ queryKey: params ? [method, params] : [method] }), setQueryData: (method: M, params: Params, data: Result) => queryClient.setQueryData([method, params], data), setQueryDataErrorsAllowed: ( diff --git a/app/forms/ip-pool-edit.tsx b/app/forms/ip-pool-edit.tsx index b794327469..6a332f4c0a 100644 --- a/app/forms/ip-pool-edit.tsx +++ b/app/forms/ip-pool-edit.tsx @@ -38,18 +38,13 @@ export function EditIpPoolSideModalForm() { const editPool = useApiMutation('ipPoolUpdate', { onSuccess(updatedPool) { - queryClient.invalidateQueries('ipPoolList') navigate(pb.ipPool({ pool: updatedPool.name })) + queryClient.invalidateQueries('ipPoolList') addToast({ content: 'Your IP pool has been updated' }) - - // Only invalidate if we're staying on the same page. If the name - // _has_ changed, invalidating ipPoolView causes an error page to flash - // while the loader for the target page is running because the current - // page's pool gets cleared out while we're still on the page. If we're - // navigating to a different page, its query will fetch anew regardless. - if (pool.name === updatedPool.name) { - queryClient.invalidateQueries('ipPoolView') - } + // specify params so we only invalidate the one we're navigating to, + // avoiding an error page flash due to clearly the current page's pool + // while navigating to another one + queryClient.invalidateQueries('ipPoolView', { path: { pool: updatedPool.name } }) }, })