TanStackT
TanStack2y ago
5 replies
brilliant-lime

Prevent server calls on loader based on client cache

I'm setting up a project with Remix and Tanstack Query. The loader is providing initial value for my view in the initial load + navigations. But between navigations, I might already have the result of that query, cached and fresh on the client and I would like to not trigger a query/fetch on the server related to the fresh queries. But since the client loader always need to call the server loader in order to get the data (I'm streaming with defer), I need a way to inform the server to skip some fetches/queries before I call it.

Any ideas how to achieve that?

My primary think was to set a cookie on client before call the server loader with info of the queries and their status.

The only API for this I could find was this, but is not 100% what I'm looking for.
getQueryClient().getQueriesData({ stale: true })
Was this page helpful?