From harness-claude
Streams server-rendered HTML progressively in Next.js using Suspense boundaries and loading.tsx for slow data fetches, preventing component blocking and enabling shell-first UX.
npx claudepluginhub intense-visions/harness-engineering --plugin harness-claudeThis skill uses the workspace's default tool permissions.
> Stream server-rendered HTML progressively using Suspense boundaries and loading.tsx
Implements React Suspense-based streaming SSR with chunked transfer and renderToPipeableStream for fast TTFB and progressive rendering on pages with slow data fetches.
Provides Next.js 15/16 data fetching patterns: server components, parallel/sequential fetches, Suspense streaming, Route Handlers, SWR/TanStack Query client fetching, revalidation, async params, caching, error handling.
Guides Next.js data fetching with SSG, SSR, ISR, fetch caching strategies like force-cache and no-store, revalidation, dynamic rendering, and generateStaticParams for data-driven apps.
Share bugs, ideas, or general feedback.
Stream server-rendered HTML progressively using Suspense boundaries and loading.tsx
loading.tsx alongside page.tsx in any route segment — Next.js wraps the page in a <Suspense> boundary automatically.<Suspense fallback={<Skeleton />}> for finer-grained streaming control.await to allow parallel fetching — initiate promises, then await them after wrapping in Suspense.use() hook in Client Components to unwrap a Promise passed as a prop, suspending until it resolves.await a fetch at the top of a layout that wraps a Suspense boundary — this negates streaming by blocking the boundary parent.loading.tsx as a Server Component — it can import static UI without any JS shipped to the client.// app/dashboard/page.tsx — parallel fetch with streaming
import { Suspense } from 'react';
import { MetricsSkeleton, ActivitySkeleton } from '@/components/skeletons';
import { Metrics } from './metrics';
import { Activity } from './activity';
export default function DashboardPage() {
// Initiate fetches in parallel — do NOT await here
const metricsPromise = fetchMetrics();
const activityPromise = fetchActivity();
return (
<div>
<Suspense fallback={<MetricsSkeleton />}>
<Metrics promise={metricsPromise} />
</Suspense>
<Suspense fallback={<ActivitySkeleton />}>
<Activity promise={activityPromise} />
</Suspense>
</div>
);
}
// app/dashboard/metrics.tsx — async Server Component
async function Metrics({ promise }: { promise: Promise<Metric[]> }) {
const metrics = await promise; // suspends until resolved
return <MetricsList items={metrics} />;
}
Next.js implements streaming via HTTP chunked transfer encoding. The server sends the initial HTML shell immediately, then streams additional HTML chunks as Suspense boundaries resolve. The browser progressively renders each chunk without waiting for the full response.
Suspense boundary placement: Each <Suspense> boundary is an independent streaming unit. Content outside boundaries renders synchronously. Deeply nested boundaries allow granular streaming — the outermost boundary controls the shell, inner boundaries control content slots.
loading.tsx convention: Next.js automatically wraps page.tsx in a Suspense boundary when loading.tsx exists in the same directory. The loading.tsx file is the fallback. This is equivalent to <Suspense fallback={<Loading />}><Page /></Suspense>.
Parallel vs sequential data fetching: Two awaits in sequence cause a waterfall — each fetch waits for the previous. Starting both fetches before any await (or using Promise.all) enables parallelism. With Suspense, each async Server Component can independently suspend without blocking siblings.
Error handling with Suspense: Pair each <Suspense> boundary with an <ErrorBoundary> (or co-locate error.tsx) to handle fetch failures gracefully within that stream segment.
Trade-offs: Streaming increases TTFB perception because the shell arrives fast, but Time to Fully Loaded may be similar. Streaming works best when content has natural priority ordering (fast shell, slower content).
https://nextjs.org/docs/app/building-your-application/routing/loading-ui-and-streaming