Skip to content

fix: increase default staleTime for paginated data #11041

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Dec 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions site/src/hooks/usePaginatedQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export function usePaginatedQuery<
searchParams: outerSearchParams,
queryFn: outerQueryFn,
prefetch = true,
staleTime = 60 * 1000, // One minute
...extraOptions
} = options;

Expand All @@ -115,7 +116,8 @@ export function usePaginatedQuery<
const currentPage = parsePage(searchParams);
const currentPageOffset = (currentPage - 1) * limit;

const getQueryOptionsFromPage = (pageNumber: number) => {
type Options = UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>;
const getQueryOptionsFromPage = (pageNumber: number): Options => {
const pageParams: QueryPageParams = {
pageNumber,
limit,
Expand All @@ -124,13 +126,13 @@ export function usePaginatedQuery<
};

const payload = queryPayload?.(pageParams) as RuntimePayload<TQueryPayload>;

return {
staleTime,
queryKey: queryKey({ ...pageParams, payload }),
queryFn: (context: QueryFunctionContext<TQueryKey>) => {
return outerQueryFn({ ...context, ...pageParams, payload });
},
} as const;
};
};

// Not using infinite query right now because that requires a fair bit of list
Expand Down Expand Up @@ -160,7 +162,6 @@ export function usePaginatedQuery<
}

const options = getQueryOptionsFromPage(newPage);

return queryClient.prefetchQuery(options);
});

Expand Down