I'm using TanStack Router, Query, and Start (though I think Start is irrelevant for this Q)
I'm wondering about loaders that are run for client-side transitions that would be run more effectively on the server-side. Consider the following:
// Some route's loader
async function loader(ctx) {
const { queryClient } = ctx.context;
const post = await queryClient.ensureQueryData(postQueryOptions(ctx.params.postId));
// Note this is much slower.
const authorStats = await queryClient.ensureQueryData(authorStatsOptions(post.authorId));
// .. maybe other dependent queries
}
I can configure this quite cleanly to run in SSR (server-side rendering) on the initial page load via this pattern in the docs:
1. client --> server
2. server runs all queries
3. client is hydrated en bulk
but if I'm navigating to this page via CSR (client-side rendering) this loader will run on the client, which adds extra latency in between dependent queries:
1. client-side nav kicks off the loader
2. client calls server for first query
3. client gets response, then continues loader, starting second query
4. client gets response, potentially kicking off other query
I recognize that both cases involve dependent queries (eg. query 2 can't run until we finish query 1), but I was wondering if there was a solution here for the added server-roundtrip latency between the queries in the CSR case? In some scenarios this may be the dominant latency driver.