/** * Single-tab adapter for browsers without SharedWorker support (e.g. Android Chrome). * * This adapter is a fallback for browsers that don't support the SharedWorker API. * It provides the same OPFS persistence as the regular persisted adapter, but without * multi-tab synchronization capabilities. * * **IMPORTANT**: This code is intended to be removed once SharedWorker support is * available in Android Chrome. Track progress at: * - LiveStore issue: https://github.com/livestorejs/livestore/issues/321 * - Chromium bug: https://issues.chromium.org/issues/40290702 * * @module */ import type { Adapter } from '@livestore/common'; import * as WorkerSchema from '../web-worker/common/worker-schema.ts'; /** * Options for the single-tab adapter. * * This adapter is designed for browsers without SharedWorker support (e.g. Android Chrome). * It provides OPFS persistence but without multi-tab synchronization. * * @see https://github.com/livestorejs/livestore/issues/321 * @see https://issues.chromium.org/issues/40290702 */ export type SingleTabAdapterOptions = { /** * The dedicated web worker that runs the LiveStore leader thread. * * @example * ```ts * import LiveStoreWorker from './livestore.worker.ts?worker' * * const adapter = makeSingleTabAdapter({ * worker: LiveStoreWorker, * storage: { type: 'opfs' }, * }) * ``` */ worker: ((options: { name: string; }) => globalThis.Worker) | (new (options: { name: string; }) => globalThis.Worker); /** * Storage configuration. Currently only OPFS is supported. */ storage: WorkerSchema.StorageTypeEncoded; /** * Warning: This will reset both the app and eventlog database. * This should only be used during development. * * @default false */ resetPersistence?: boolean; /** * By default the adapter will initially generate a random clientId (via `nanoid(5)`), * store it in `localStorage` and restore it for subsequent client sessions. */ clientId?: string; /** * By default the adapter will initially generate a random sessionId (via `nanoid(5)`), * store it in `sessionStorage` and restore it for subsequent client sessions in the same tab. */ sessionId?: string; experimental?: { /** * When set to `true`, the adapter will always start with a snapshot from the leader * instead of trying to load a snapshot from storage. * * @default false */ disableFastPath?: boolean; }; }; /** * Creates a single-tab web adapter with OPFS persistence. * * **This adapter is a fallback for browsers without SharedWorker support** (notably Android Chrome). * It provides the same persistence capabilities as `makePersistedAdapter`, but without multi-tab * synchronization. Each browser tab runs its own independent leader worker. * * In most cases, you should use `makePersistedAdapter` instead, which automatically falls back * to this adapter when SharedWorker is unavailable. * * **Limitations**: * - No multi-tab synchronization (each tab operates independently) * - No devtools support (requires SharedWorker) * - Opening multiple tabs with the same storeId may cause data conflicts * * @see https://github.com/livestorejs/livestore/issues/321 - LiveStore tracking issue * @see https://issues.chromium.org/issues/40290702 - Chromium SharedWorker bug * * @example * ```ts * import { makeSingleTabAdapter } from '@livestore/adapter-web' * import LiveStoreWorker from './livestore.worker.ts?worker' * * // Only use this directly if you specifically need single-tab mode. * // Prefer makePersistedAdapter which auto-detects SharedWorker support. * const adapter = makeSingleTabAdapter({ * worker: LiveStoreWorker, * storage: { type: 'opfs' }, * }) * ``` */ export declare const makeSingleTabAdapter: (options: SingleTabAdapterOptions) => Adapter; //# sourceMappingURL=single-tab-adapter.d.ts.map