Thin Client
Learn how to set up the thin browser client, which talks to your backend with no local database.The default browser client: about 160 KB gzipped, with no Wasm and no local storage. Your main backend runs every query under the signed-in user's policies and sends finished rows, and writes commit on the server.
When to pick it
Jazz has two browser clients. Both use the same schema, queries, permissions and Db API, so you
can start thin and upgrade to local-first
later without changing app code.
| Thin Client | Local-First Client | |
|---|---|---|
| Bundle | about 160 KB gzipped | adds the Wasm engine (about 4 MB gzipped), loaded as its own chunk |
| Queries run | on your backend, under the user's policies | in the browser, against a local replica |
| Writes show up | after one round trip | instantly, then sync |
| Offline | no | yes, reads and writes |
| Local storage | none | IndexedDB, per account |
| Wasm and workers | none | a Wasm engine in a shared worker |
| Setup | nothing beyond JazzProvider | a client loader and a few bundler lines |
Both need React 19 or later for the React bindings (jazz-tools declares react >=19, so npm
refuses to install it next to React 18).
Pick the thin client by default. Pick local-first when users need instant UI on every change, work offline, or keep large working sets that should not round-trip on every read.
Connect
The thin client is the default: JazzProvider in React, Vue or Svelte, or createJazzClient
from jazz-tools/client, without a client loader.
App.tsximport { JazzProvider } from "jazz-tools/react";function Root() {return (<JazzProvider config={{ serverUrl: "/jazz" }} signedOut={<SignIn />}><App /></JazzProvider>);}
Besides signedOut, the provider takes loading (shown while Jazz starts or switches users;
by default a "Loading…" line) and error (shown when Jazz can't start; by default a message
with a "Try again" button). See Framework patterns.
In the Next.js App Router, JazzProvider is a client component. Put it in a file that starts
with "use client" and render that from app/layout.tsx around {children}:
app/providers.tsx"use client";import { JazzProvider } from "jazz-tools/react";export function Providers({ children }: { children: React.ReactNode }) {return (<JazzProvider config={{ serverUrl: "/jazz" }} signedOut={<SignIn />}>{children}</JazzProvider>);}
Server components and route handlers read through
jazz.forReqUser instead.
App.vue<script setup lang="ts">import { JazzProvider } from "jazz-tools/vue";</script><template><JazzProvider :config="{ serverUrl: '/jazz' }"><TodoApp /><template #signedOut><SignIn /></template></JazzProvider></template>
After your own sign-in, call refresh() from useJazzSession() (from jazz-tools/vue).
See Framework Patterns for the other Vue APIs.
App.svelte<script lang="ts">import { JazzProvider } from "jazz-tools/svelte";</script><JazzProvider config={{ serverUrl: "/jazz" }}><TodoApp />{#snippet signedOut()}<SignIn />{/snippet}</JazzProvider>
After your own sign-in, call refresh() on getJazzSession() (from jazz-tools/svelte,
called during component setup). In SvelteKit, render the provider only in the browser; see
Framework Patterns for that and the other Svelte APIs.
app.tsimport { createJazzClient } from "jazz-tools/client";import { app } from "./jazz.generated";const session = await createJazzClient({ serverUrl: "/jazz" });// After your own sign-in or sign-out, ask your backend again.authClient.onSessionChange(() => void session.refresh());// session.db throws while no one is signed in.if (session.getSnapshot().status === "ready") {const todos = await session.db.all(app.todos);}
await createJazzClient(…) resolves once the session started, and rejects if it can't. To
show a loading screen and a failed-to-start screen while it starts, use startJazzClient: it
returns the session at once, in "starting".
app.tsimport { startJazzClient } from "jazz-tools/client";const session = startJazzClient({ serverUrl: "/jazz" });const render = () => {const { status, error } = session.getSnapshot();if (status === "starting" || status === "transitioning") showLoading();else if (status === "error") showError(error, () => void session.retry());else if (status === "signed-out") showSignIn();else if (status === "ready") showApp(session.db);};session.subscribe(render);render();
A failed start leaves the session open, in "error": retry() starts it again, and
session.close() is yours to call when the app is done with it.
Sign-in
Both clients sign in the same way: they ask your main backend at /jazz who is signed in, with
your app's own session cookie, and your backend's authenticate decides who that user is. The
client asks on start, when the page regains focus and when another tab signs in or out. After your
own sign-in or sign-out, call refresh() on the session (from useJazzSession() in React, Vue and
Solid, getJazzSession() in Svelte) so the change shows at once. To let people in before they sign
up, start them as guests on a device account (initial: "device"),
a local-first friendly account whose key stays on the device. The browser never holds a Jazz key or token. See How Auth Works.
Reads and writes
Both clients return the same Db: queries, subscribe, insert, update,
upsert, delete, transactions and the framework hooks work unchanged.
- Thin client. A write shows after one round trip to your backend.
wait({ tier })resolves once the server has committed the write, whichever tier you pass: that already meets every tier. - Local-first client. A write shows instantly in every local query, then syncs.
wait({ tier })takes a durability tier (localorglobal) to wait for the point you need.
Both take the same call, for example await db.insert(app.todos, todo).wait({ tier: "global" }),
so code that waits works on either client.
Options
Both clients take these options, in createJazzClient(config) or <JazzProvider config={…}>:
| Option | Default | What it does |
|---|---|---|
serverUrl | /jazz | Where your main backend mounts Jazz. Set it only if you mount it somewhere else |
initial | "signed-out" | "device" starts visitors as guests on a device account |
linkDeviceAccountOnSignUp | true | Link the device account to a user who signs up; turn off on shared devices |
clearOnSignOut | false | Wipe the account's local data on sign-out, for shared devices |
createJazzClient needs a config ({} for the defaults) and refuses an option it doesn't take, naming
the ones it does, rather than ignoring it.
Both clients also set window.__jazz, the page's sync status and storage controls for tests and
agents (window.__jazz.status(), waitForSync(), clearStorage()). The name is Jazz's: if your
app or another library already set window.__jazz, Jazz leaves it alone, warns once on the
console and goes without the handle. Rename your own global to get the handle back.
Limitations
Each is an explicit "not supported" error:
- no offline use: while the backend is unreachable, reads and subscriptions wait and are answered after the reconnect; writes are not optimistic: they show after one round trip, and
wait({ tier })resolves when the server committed them, whatever the tier - no attributed writes
- no streaming inside a transaction
- text edits with
editedFromon merge text columns are rejected (NotObserved) for now; use the local-first client for collaborative text editing - pending writes live in memory only: a write the server hasn't answered yet is lost if the page reloads or closes (see Pending writes below)
- a single write, and a single answer to a query, can be at most 32 MiB. The client refuses a
larger write itself; streamed writes (
insertStreamingand the like) go in pieces, so a larger file uploads fine. The server answers a larger result with aTooLargeerror for that query alone (ending a live query) and keeps the session, so one very large row fails every query that includes it. Read such a value a page at a time with a range select, such asselect({ content: { from, to } }), until streaming reads arrive
Pending writes
When the socket drops, the client reconnects on its own and resends any write the server hadn't
answered. Standalone inserts, updates, upserts, deletes and restores carry a key the server
deduplicates by, so a resend lands exactly once. getSyncStatus() and useSyncStatus() show
whether the client is connected and how many writes still wait for an answer.
A write ends with ThinConnectionLostError (from jazz-tools/thin) only when the connection ends
for good while it waits: after refresh() signs in someone else, after disconnect(), or
when the client closes. It may or may not have committed, so read before you retry. A transaction
in flight when the socket drops ends the same way.
When the server refuses the user, because jazz.revokeUser ended their session or authenticate
no longer names them, the client stops: a write it hadn't sent yet ends with
ThinRequestNotSentError (also from jazz-tools/thin), whose message names the refusal ("the
server refused this client's sign-in (…)"). It didn't commit. The session then asks your backend
who is signed in, and signs out. A write already sent ends with ThinConnectionLostError as above.
When the server refuses the user's sign-in (their session ended, or your backend called
jazz.revokeUser), the link shows offline with reason auth, and new writes wait in case your
app signs them in again. Once Jazz signs them out, those writes end with ThinRequestNotSentError,
whose message says the server refused the sign-in. They never reached the server. The sign-out
logs how many it dropped.
Pending writes are kept in memory, not on disk. To warn before the user leaves with unsent changes:
window.addEventListener("beforeunload", (event) => {if (db.getSyncStatus().pendingUploads > 0) event.preventDefault();});
For writes that survive a reload, upgrade to local-first.
Upgrading to local-first
To keep initial loading fast, start with the thin client and upgrade to the local-first client
when it's needed. Hand the provider a loader to upgrade in the background after the first load, or
call upgradeToLocalFirst when your app needs it (below). The session keeps the same Db: live queries and listeners carry on, restarting from the
local-first client's first result, and the thin client's pending writes finish first:
<JazzProvider config={{ serverUrl: "/jazz", client: () => import("jazz-tools/local-first") }}>
The dynamic import lives in your code, so the local-first client and its Wasm become a separate
chunk: apps that never pass client never download it.
To upgrade only when you need to, for example when a user opens an editor or goes offline, call the hook instead:
const { upgradeToLocalFirst } = useDb();await upgradeToLocalFirst(() => import("jazz-tools/local-first"));
Without a framework, call the same method on session.db:
await db.upgradeToLocalFirst(() => import("jazz-tools/local-first")). The session upgrades in place,
so you keep using the same Db. See Local-First Client.