Loaders and Prefetching

TanStack Start routes can have isomorphic loader functions that run on the server for the initial pageload and on the client for subsequent client-side navigations.

These three links navigate to subpages that show chat messages from different channels. Notice how client navigations between these pages work differently.

Awaiting ensureQueryData will block rendering of the page until that data is available and calling prefetchQuery will start the request but not block. Loaders also run during prefetching, triggered by the cursor mousing onto a link in TanStack Start by default.

When to use a loader

Loading a query in a loader ejects from the convenience of component-local reasoning through useSuspenseQuery where a component fetching its own data to the cold reality of fast page loads when you need it.

4
User 40335/22/26, 2:08 AM

Hi Nipunn- I'll be late to make the meeting tomorrow morning

6
User 62085/14/26, 6:11 AM

hi Nipunn; how's the weather in SF?

4
User 49315/13/26, 2:01 AM

hello Jamie, how's the weather in SF?

9
User 91135/11/26, 1:34 PM

hi Jamie- how was your weekend?

9
User 91135/11/26, 1:34 PM

hello Nipunn; how was your weekend?

9
User 91135/11/26, 1:34 PM

Hi Nipunn! I'll be late to make the meeting tomorrow morning

9
User 91135/11/26, 1:34 PM

Hi Nipunn... how's the weather in SF?

9
User 91135/11/26, 1:34 PM

Hi Nipunn, Could you let the customer know we've fixed their issue?

9
User 91135/11/26, 1:34 PM

hello Jamie- how was your weekend?

9
User 91135/11/26, 1:34 PM

Hi Jamie; how's the weather in SF?

9
User 91135/11/26, 1:34 PM

hi James, I'll be late to make the meeting tomorrow morning

9
User 99603/20/26, 11:39 AM

hey James! how's the weather in SF?

8
User 87303/18/26, 10:44 AM

hello Jamie... how's the weather in SF?

8
User 87303/18/26, 10:44 AM

hi Emma, Could you let the customer know we've fixed their issue?

2
User 27062/4/26, 3:29 PM

Hi Emma! how was your weekend?

2
User 27062/4/26, 3:29 PM

hello Jamie- I'll be late to make the meeting tomorrow morning

2
User 27062/4/26, 3:29 PM

Hi Jamie; how's the weather in SF?

2
User 23571/27/26, 9:42 PM

hi Nipunn, what's your favorite ice cream place?

2
User 23571/27/26, 9:42 PM

Hi Jamie! Could you let the customer know we've fixed their issue?

9
User 90101/15/26, 5:01 PM

hello Jamie... how's the weather in SF?

1export const Route = createFileRoute('/loaders/ensure')({
2 loader: async (opts) => {
3 await opts.context.queryClient.ensureQueryData(
4 convexQuery(api.messages.list, {}),
5 );
6 },
7 component: () => {
8 const { data } = useQuery(
9 convexQuery(api.messages.list, {})
10 );
11 },
12})

Learn More

Tanner's An Early Glimpse of TanStack Start video

TanStack Router Preloading Guide