Skip to content

prefetchQuery causes timeout during build with Next.js 15.4.4 and TanStack Query 5.83.0 #9507

Answered by TkDodo
Toddynn asked this question in Q&A
Discussion options

You must be logged in to vote

makeQueryClient, if taken from the docs, is meant to work in both environments. You even have the isServer check in your code, so it should just create a new QueryClient every time, just with the same options. Unless you maybe need different options?

I just saw that you are prefetching for the same queryKey in parallel. Is that on purpose? I think what you want is:

queryClient.prefetchInfiniteQuery({
  queryKey: [private_get_all_user_petim_by_type_id_query_key],
  queryFn: async ({ pageParam }) =>
    await privateGetAllUserPetimByTypeId<GoodThingPetim>({
      petim_type_id: petim_type.id,
      page: pageParam,
    }),
  initialPageParam: 1,
  getNextPageParam: () => ...
  pages: 2,
}),

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@Toddynn
Comment options

@TkDodo
Comment options

Answer selected by Toddynn
@Toddynn
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants