Skip to content

createVexServerClient

createVexServerClient(props?): VexServerClient

Defined in: packages/next/src/cache/createVexServerClient.ts:36

Creates a server-only Convex read client safe to use in prerenderable Next.js routes.

Wraps ConvexHttpClient from convex/browser instead of convex/nextjs’s fetchQuery, which hard-codes client.setFetchOptions({ cache: "no-store" }) — the reason every route calling it builds dynamic (ƒ). This client never sets that option, so a route calling only query() can be prerendered and governed by the route’s own export const revalidate.

Every query() call is deduped via React.cache for the lifetime of one request: two identical (query, args) calls — e.g. generateMetadata and its page both reading the same document — resolve from a single Convex round trip instead of two.

React.cache is instantiated fresh inside every createVexServerClient() call, so that dedupe only holds across calls sharing the SAME client instance — two clients built in two different modules cannot share a round trip even when they read identical (query, args). Each app therefore creates exactly one instance, exported from its own src/lib/vex.ts, and every route or component imports that shared vex rather than calling createVexServerClient() itself.

VexServerClientOptions = {}

Client configuration.

VexServerClient

A VexServerClient whose query method is deduped per request.

When no url is given and process.env.NEXT_PUBLIC_CONVEX_URL is unset.