Advanced

SSR Safety

How svelte-idb safely handles server-side rendering without IndexedDB.

How it works

IndexedDB only exists in browsers. When your SvelteKit app renders on the server, svelte-idb detects the server environment and returns safe no-op implementations instead of throwing errors. This means you can use createDB() and createReactiveDB() directly in your components without wrapping them in onMount or browser checks.

SSR strategies

Configure the ssr option in your database config to control server-side behavior.

NameTypeDescription
'noop' defaultReturn safe defaults (empty arrays, 0, undefined) on server
'throw' strictThrow an error if any IndexedDB operation runs on the server
function customCall a custom function with the operation name

Configuration

ssr-config.ts

SSR return values

When using the default "noop" strategy, operations return these safe defaults on the server:

NameTypeDescription
add() IDBValidKeyReturns 0
put() IDBValidKeyReturns 0
get() T | undefinedReturns undefined
getAll() T[]Returns []
delete() voidReturns undefined
clear() voidReturns undefined
count() numberReturns 0

LiveQuery instances created on the server will have loading: false, current set to their initial value, and will never re-query.