AI agents: fetch the documentation index at llms.txt. Markdown versions are available by appending .md to any page URL, including this page's markdown.
Server utilities
Server-side bootstrap prefetching and serialization for Next.js Server Components.
Prefetch sync data on the server and pass it to client components, eliminating the client-side bootstrap request.
import {
prefetchBootstrap,
prefetchModels,
serializeBootstrapSnapshot,
encodeBootstrapSnapshot,
} from "@stratasync/next/server";prefetchBootstrap
Fetches the full bootstrap dataset from the sync server.
// app/dashboard/page.tsx (Server Component)
import {
prefetchBootstrap,
serializeBootstrapSnapshot,
} from "@stratasync/next/server";
export default async function DashboardPage() {
const snapshot = await prefetchBootstrap({
endpoint: process.env.SYNC_ENDPOINT!,
authorization: `Bearer ${await getServerToken()}`,
groups: ["workspace-abc"],
timeout: 10000,
});
const serialized = await serializeBootstrapSnapshot(snapshot);
return <DashboardClient bootstrapData={serialized} />;
}Signature: prefetchBootstrap(options: PrefetchBootstrapOptions): Promise<BootstrapSnapshot>
PrefetchBootstrapOptions
| Option | Type | Default | Description |
|---|---|---|---|
endpoint | string | Required | Sync server endpoint URL. |
authorization | string | - | Authorization header value (such as "Bearer token"). |
headers | Record<string, string> | - | Additional request headers. |
models | string[] | - | Specific models to fetch (all if omitted). |
groups | string[] | - | Sync groups to include. |
schemaHash | string | - | Expected schema hash for validation. |
timeout | number | 10000 | Request timeout in milliseconds. |
BootstrapSnapshot
interface BootstrapSnapshot {
version: 1;
schemaHash: string;
lastSyncId: number;
firstSyncId?: number;
groups: string[];
rows: ModelRow[];
fetchedAt: number;
rowCount?: number;
}serializeBootstrapSnapshot
Serializes a snapshot for transfer across the Server Component boundary. Supports gzip compression.
const payload = await serializeBootstrapSnapshot(snapshot);
// payload.version: 1
// payload.encoding: "json" | "gzip-base64"
// payload.data: stringSignature: serializeBootstrapSnapshot(snapshot: BootstrapSnapshot, options?: SerializeBootstrapOptions): Promise<BootstrapSnapshotPayload>
SerializeBootstrapOptions
| Option | Type | Default | Description |
|---|---|---|---|
compress | boolean | true (if CompressionStream available) | Whether to gzip-compress the data. |
BootstrapSnapshotPayload
interface BootstrapSnapshotPayload {
version: 1;
encoding: "json" | "gzip-base64";
data: string;
}When compression is available (Node.js 18+), data is gzip-compressed and base64-encoded to reduce prop size.
encodeBootstrapSnapshot
Wraps serializeBootstrapSnapshot + JSON.stringify into a single JSON string.
const encoded = await encodeBootstrapSnapshot(snapshot);
// encoded is a JSON string containing the BootstrapSnapshotPayloadSignature: encodeBootstrapSnapshot(snapshot: BootstrapSnapshot, options?: SerializeBootstrapOptions): Promise<string>
prefetchModels
Prefetch a subset of models for a specific page.
// app/dashboard/page.tsx (Server Component)
import { prefetchModels } from "@stratasync/next/server";
export default async function DashboardPage() {
const result = await prefetchModels({
endpoint: process.env.API_URL + "/sync/prefetch",
authorization: `Bearer ${await getServerToken()}`,
models: [
{ name: "Project", limit: 10 },
{ name: "Task", filter: { status: "active" }, limit: 50 },
],
timeout: 5000,
});
return <DashboardClient prefetchedData={result} />;
}Signature: prefetchModels(options: PrefetchOptions): Promise<PrefetchResult>
PrefetchOptions
| Option | Type | Default | Description |
|---|---|---|---|
endpoint | string | Required | Prefetch API endpoint. |
authorization | string | - | Authorization header. |
models | Array<{ name, filter?, limit? }> | Required | Models to prefetch with optional filters. |
timeout | number | 5000 | Request timeout in milliseconds. |
PrefetchResult
Pass directly through the Server Component boundary as props:
interface PrefetchResult {
data: Record<string, PrefetchedData>;
}
interface PrefetchedData {
modelName: string;
data: Record<string, unknown>[];
fetchedAt: number;
}Complete SSR example
See SSR and bootstrap for a complete Next.js App Router example.