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.
| Name | Type | Description |
|---|---|---|
'noop' | default | Return safe defaults (empty arrays, 0, undefined) on server |
'throw' | strict | Throw an error if any IndexedDB operation runs on the server |
function | custom | Call 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:
| Name | Type | Description |
|---|---|---|
add() | IDBValidKey | Returns 0 |
put() | IDBValidKey | Returns 0 |
get() | T | undefined | Returns undefined |
getAll() | T[] | Returns [] |
delete() | void | Returns undefined |
clear() | void | Returns undefined |
count() | number | Returns 0 |
LiveQuery instances created on the server will have loading: false, current set to their initial value, and will never re-query.