Tutorials

How to Prefetch React Queries Without a Route Loader in tRPC 11.32

tRPC 11.32 introduces useLoadHandles(), allowing React pages to start multiple queries without a route loader. Here's how to pass typed handles to components and avoid unnecessary request waterfalls.

A React page needs two things: a post and its comments.

The post appears first. Comments are rendered inside another component, so their request begins only after that component mounts.

Nothing is technically broken. Both requests succeed, and the page eventually displays everything.

But look at the network activity.

Instead of starting together, the requests may form a waterfall: the second request begins after the first one has already finished.

For a page with several nested components, those delays can accumulate.

Route loaders solve this by starting requests before rendering the page. Yet not every React application uses a router with loaders. Sometimes the page is simply a component, and its data requirements are spread across several children.

On November 27, 2026, tRPC released @trpc/tanstack-react-query 11.32.0, introducing useLoadHandles().

The hook allows a component to start several tRPC queries together, without a route loader and without waiting for their results before returning JSX.

Why requests become sequential

Consider a typical component structure:

function PostPage({ id }: { id: string }) {
  return <Post id={id} />;
}

The Post component fetches its own data and then renders Comments.

If Comments fetches its data only after Post has finished loading, the network activity follows this pattern:

post.byId       |----------|
comment.list                |----------|

The comments request has to wait for the post component to finish loading and render its children.

But suppose both procedures accept an ID already available from the URL.

There is no actual data dependency between them.

The page can request the post and comments simultaneously:

post.byId       |----------|
comment.list    |----------|

This is the problem useLoadHandles() addresses.

It brings the query-starting logic into the page component while allowing the child components to remain responsible for displaying their own data.

1. Update tRPC

In an existing tRPC 11 application using TanStack Query:

pnpm add @trpc/tanstack-react-query@^11.32.0

The following examples assume your application already has a configured tRPC client, useTRPC() hook, and TanStack Query provider.

They also assume these two tRPC procedures exist:

post.byId({ id: string })
comment.list({ postId: string })

For the example, post.byId returns a post with a title, and comment.list returns an array of comments containing id and body.

The new API is imported from:

import {
  prefetchEntry,
  useLoadHandles,
} from "@trpc/tanstack-react-query/unstable-handles";

The unstable-handles path is intentional.

These APIs are still experimental, and their contracts may change in minor releases.

2. Start both queries in the page component

Create a component that builds the entries and starts them together:

import { Suspense } from "react";
import {
  prefetchEntry,
  useLoadHandles,
} from "@trpc/tanstack-react-query/unstable-handles";

import { useTRPC } from "./trpc/client";
import { Post } from "./Post";
import { Comments } from "./Comments";

export function PostPage({ id }: { id: string }) {
  const trpc = useTRPC();

  const handles = useLoadHandles(trpc, {
    post: prefetchEntry(trpc.post.byId, { id }),
    comments: prefetchEntry(trpc.comment.list, {
      postId: id,
    }),
  });

  return (
    <>
      <Suspense fallback={<p>Loading post...</p>}>
        <Post handle={handles.post} />
      </Suspense>

      <Suspense fallback={<p>Loading comments...</p>}>
        <Comments handle={handles.comments} />
      </Suspense>
    </>
  );
}

There are two separate operations here.

prefetchEntry() describes the query that should be started. Creating an entry does not send a request.

useLoadHandles() receives the entries and starts their queries when the page renders.

It does not await the results.

Instead, it returns handles that identify the corresponding queries.

Conceptually, the process looks like this:

flowchart TD
    A["PostPage renders"] --> B["useLoadHandles"]
    B --> C["post.byId starts"]
    B --> D["comment.list starts"]
    C --> E["TanStack Query cache"]
    D --> E
    E --> F["Post reads its handle"]
    E --> G["Comments reads its handle"]

The important part is that both queries begin from the parent component.

Neither has to wait for the other component to finish rendering.

3. Read the data through handles

A handle does not contain the fetched data.

It contains information needed to identify the query, including its query key and input.

The child component uses fromHandle() to reconstruct the appropriate TanStack Query options.

For example, the Post component can read its data like this:

import { useSuspenseQuery } from "@tanstack/react-query";
import {
  fromHandle,
  type inferQueryHandle,
} from "@trpc/tanstack-react-query/unstable-handles";

import { useTRPC } from "./trpc/client";
import type { TRPC } from "./trpc/client";

type PostHandle = inferQueryHandle<
  TRPC["post"]["byId"]
>;

export function Post({
  handle,
}: {
  handle: PostHandle;
}) {
  const trpc = useTRPC();

  const { data } = useSuspenseQuery(
    fromHandle(trpc, handle)
  );

  return <h1>{data.title}</h1>;
}

The TRPC type represents your application’s typed tRPC options proxy.

If your project has not exported it yet, the client setup can declare it:

import type { TRPCOptionsProxy } from "@trpc/tanstack-react-query";
import type { AppRouter } from "../server/router";

export type TRPC = TRPCOptionsProxy<AppRouter>;

Adjust the import paths to match your project.

The comments component follows the same pattern:

import { useSuspenseQuery } from "@tanstack/react-query";
import {
  fromHandle,
  type inferQueryHandle,
} from "@trpc/tanstack-react-query/unstable-handles";

import { useTRPC } from "./trpc/client";
import type { TRPC } from "./trpc/client";

type CommentsHandle = inferQueryHandle<
  TRPC["comment"]["list"]
>;

export function Comments({
  handle,
}: {
  handle: CommentsHandle;
}) {
  const trpc = useTRPC();

  const { data } = useSuspenseQuery(
    fromHandle(trpc, handle)
  );

  return (
    <ul>
      {data.map((comment) => (
        <li key={comment.id}>{comment.body}</li>
      ))}
    </ul>
  );
}

Notice that neither component needs to reconstruct the input.

Post does not need to know which ID was passed into the original request, and Comments does not have to repeat the postId argument.

Both receive typed handles that refer to queries already started by the page.

They also use the same TanStack Query cache.

If the requested data is already cached, the reader can use it instead of issuing an unnecessary duplicate request.

4. Suspense and error handling

useLoadHandles() does not suspend the page while its requests are running.

The loading state belongs to the components reading the handles.

That is why the earlier example uses separate Suspense boundaries for Post and Comments.

If the post is ready before the comments, React can display it while the comments section continues loading.

There is no need to hold back the entire page.

Errors follow a similar pattern.

The hook itself does not wait for a query to finish, so a failed request reaches the component reading that query.

With useSuspenseQuery(), the error can be handled by the nearest React error boundary.

Suspense alone is not an error boundary. A production application should provide an appropriate error boundary as well.

For retrying failed queries, tRPC’s documentation recommends integrating TanStack Query’s QueryErrorResetBoundary.

There is a reason for that recommendation.

Repeatedly rendering the same component does not automatically restart a failed query. Without resetting the query’s error state, an ordinary error-boundary reset can cause the same error to be thrown again.

5. Will every render start new requests?

No.

This is one of the details addressed in the implementation.

Once the page is mounted, an ordinary rerender does not automatically restart the same entries.

However, changing the query input or relevant loading options can start a different query.

For example:

<PostPage id="42" />

and:

<PostPage id="43" />

refer to different query inputs.

The hook responds accordingly.

It can also start entries again when a page returns after being unmounted, or when React retries rendering before the component successfully mounts.

That does not necessarily mean another network request occurs.

TanStack Query can reuse a request already in progress or use fresh cached data.

The implementation also avoids repeatedly restarting a failed query simply because the component renders again.

6. Is useLoadHandles better than a route loader?

Not necessarily.

Both approaches help organize queries, but they start them at different moments.

Behavior Route loader with loadHandles() Component with useLoadHandles()
Queries start During navigation, before page rendering When the page renders
Waits for results Depends on entry type Never
Can return fetched data for redirects Yes, with waiting entries No
Handles available to components Yes Yes
Requires route loader Yes No

A route loader can start requests earlier, before the page component is even rendered.

That makes it preferable when the framework already provides a suitable loader.

For example, TanStack Router and TanStack Start can initiate data loading during navigation.

useLoadHandles() is useful when no such loader exists, including ordinary single-page applications, client-side Next.js pages, and dialogs with their own data requirements.

It should be treated as another entry point for the same handle-based architecture, not a replacement for every existing prefetching mechanism.

7. What changes in Next.js App Router?

Next.js introduces a separate consideration.

A client component can still be rendered on the server during the initial page request.

If that component calls useLoadHandles(), queries can begin during server rendering.

But the browser needs access to the server’s TanStack Query cache state.

Without hydration, the client starts with an empty cache and may request the same data again during hydration.

The new hook does not automatically transfer that cache state.

tRPC recommends using TanStack Query’s ReactQueryStreamedHydration when following this pattern in Next.js App Router.

Otherwise, you may see duplicate requests even though the initial server rendering already loaded the data.

On client-side navigation, the behavior is different again: requests begin when the page component renders in the browser.

This is another reason not to assume that useLoadHandles() and a server-side route loader are equivalent in every environment.

What it cannot fix

There is one situation where starting queries together is impossible without changing how the application obtains its data.

Suppose comment.list requires an internal post ID that is only returned by post.bySlug.

The comments request cannot begin until the post request has returned that ID.

This is a genuine data dependency, not simply a component-rendering problem.

useLoadHandles() cannot remove that dependency.

One possible solution is to change the comments procedure so it accepts the slug already present in the URL.

The server can resolve the slug to the internal ID without requiring another browser round trip.

Another option is to return related information together when that better matches the application’s data requirements.

The hook is most useful when queries are independent but would otherwise begin at different times because of the component tree.

What changed in tRPC 11.32.0?

The new useLoadHandles() hook makes handle-based prefetching available directly from a React component.

Previously, loadHandles() needed a suitable place to perform asynchronous work, such as a route loader, server component, or event handler.

Now a page without those mechanisms can start several queries during rendering and immediately pass their handles to child components.

The children continue using normal TanStack Query hooks to read the results.

The improvement is particularly useful for pages where the necessary query inputs are already known from the URL but the components would otherwise start requests at different times.

It does not eliminate legitimate data dependencies, guarantee fewer network requests in every rendering environment, or replace cache hydration.

Still, for an application without route loaders, it provides a relatively small change to where data fetching begins.

Instead of allowing the component tree to determine when each independent request starts, the page can initiate them together.

External Sources used for this article

Related Articles

View all →