Server rendering
For Admin panel only projects, the login is /, the home page is /dashboard, and other panel pages omit the /admin prefix. Components use @/components and @/components/ui. API endpoints such as /api/admin/users/export keep their paths. Examples below use the combined public website + admin panel layout; generated standalone guides use the app’s actual paths.
Read data on the server
Server Components can call the router directly, without an HTTP request to their own app.
This example keeps the title outside the request-time boundary:
// src/app/api-status/page.tsx
import { connection } from "next/server";
import { Suspense } from "react";
import { Skeleton } from "@/components/ui/skeleton";
import { getCaller } from "@/trpc/server";
async function StatusValue() {
await connection();
const health = await getCaller().health();
return <output>{health.status}</output>;
}
export default function Page() {
return (
<main>
<h1>API status</h1>
<Suspense fallback={<Skeleton className="h-5 w-16" />}>
<StatusValue />
</Suspense>
</main>
);
}
For a private server read, choose the protected procedure for that data. Keep auth-dependent calls outside shared use cache functions and process-global caches.
Prefetch and hydrate
Prefetch when a Client Component needs initial server data and later browser updates.
1. Create the query component
// src/app/(admin)/admin/(protected)/profile/profile-details.tsx
"use client";
import { useSuspenseQuery } from "@tanstack/react-query";
import { useTRPC } from "@/trpc/client";
export function ProfileDetails() {
const trpc = useTRPC();
const { data } = useSuspenseQuery(trpc.auth.me.queryOptions());
return (
<p>
{data.name} · {data.email}
</p>
);
}
2. Prefetch inside a narrow boundary
This example is an administrator page. It authorizes the route before prefetching:
// src/app/(admin)/admin/(protected)/profile/page.tsx
import { connection } from "next/server";
import { Suspense } from "react";
import { Skeleton } from "@/components/ui/skeleton";
import { requireAdmin } from "@/lib/admin-auth";
import { HydrateClient, prefetch, trpc } from "@/trpc/server";
import { ProfileDetails } from "./profile-details";
async function ProfileData() {
await connection();
await requireAdmin();
void prefetch(trpc.auth.me.queryOptions());
return (
<HydrateClient>
<ProfileDetails />
</HydrateClient>
);
}
export default function Page() {
return (
<main>
<h1>Profile</h1>
<p>Your account details.</p>
<Suspense fallback={<Skeleton className="h-5 w-64 max-w-full" />}>
<ProfileData />
</Suspense>
</main>
);
}
With Next.js Cache Components, establish request time before using the prefetch/hydration helpers. Awaiting connection() under Suspense does this; awaiting request headers or cookies also establishes the boundary.
The server QueryClient is request-scoped. Pending queries can stream to the browser, where a stable QueryClient reuses them. A failed authenticated prefetch does not replace route authorization.
References: tRPC App Router setup, TanStack Query advanced SSR.