vishalbalaji / trpc-svelte-query-adapter

A simple adapter to use `@tanstack/svelte-query` with trpc, similar to `@trpc/react-query`.
71 stars 6 forks source link

createServerQuery not respecting staletime #10

Closed ralphwest1 closed 1 year ago

ralphwest1 commented 1 year ago

I have the following code in a /+page.ts

export const load = (async (evt) => {
  const { queryClient } = await evt.parent();
  const client = trpcQuery(evt, queryClient);
  return {
    data: client.test.list.createServerQuery({}, { staleTime: 10 * 60 }),
  };
}) satisfies PageLoad;

Every time I navigate to the page the query is refetched and the staleTime is not used.

I understand that If I refresh the browser the queryClient is cleared out, but I was expecting the stale time to respected for client-side navigation.

Is there a setting where I can enable respecting staleTime for client-side navigation?

vishalbalaji commented 1 year ago

Hey @ralphwest1, sorry for the delayed response. Is this the case only when using createServerQuery, or is staleTime not respected even on the client side, with regular createQuery?

ralphwest1 commented 1 year ago

Hi @vishalbalaji, stale time is respected on the client if I use createQuery. But not when I use createServerQuery in a +page.ts

vishalbalaji commented 1 year ago

Just for reference, could you share a screenshot of the network requests for when you use it in +page.ts and from a component or share a small reproduction on StackBlitz?

vishalbalaji commented 1 year ago

@ralphwest1, I made some changes to how the queries are pre-fetched and have just pushed up a new version. Now the prefetch should only happen if the data is not already in the queryCache and therefore respect staleTime. Could you test out v2.1.0 and let me know if the issue still persists?

ralphwest1 commented 1 year ago

@vishalbalaji I've tested v2.1.0 and it appears to be working great.

vishalbalaji commented 1 year ago

Alrighty then, glad to hear it. Thanks for opening the issue, closing it now.