y-indexeddb is a database adapter for Yjs, providing robust persistence for Yjs documents directly within the browser's IndexedDB. It enables critical features such as offline editing and significantly reduces the amount of data exchanged between a server and client by storing the full document state locally. The package is actively maintained, with the current stable version being 9.0.12, and receives frequent patch and minor updates. Its primary differentiation lies in its tight integration with the Yjs ecosystem, offering reliable CRDT-based persistence for collaborative applications without requiring a separate server-side database, making it ideal for browser-based, offline-first applications leveraging Yjs.
npm install y-indexeddbVerified import paths — ran on the pinned version, not inferred.
Demonstrates initializing a Yjs document with IndexedDB persistence and handling the 'synced' event to confirm data loading or initial content creation, including storing custom metadata.
Ensure all calls to `provider.clearData()` are `await`ed or handle the returned Promise explicitly (e.g., `provider.clearData().then(...)`).
Migrate to ESM `import` statements (e.g., `import { IndexeddbPersistence } from 'y-indexeddb';`). If using CommonJS, ensure your build setup correctly handles the `exports` map, or consider upgrading Node.js/bundler versions.Rely on the automatic destruction mechanism when destroying the Yjs document. Only manually call `provider.destroy()` if you need to specifically terminate the IndexedDB connection before the Yjs document itself is destroyed, or if managing multiple persistence providers for a single document.
Check the `package.json` for `y-indexeddb`'s peer dependency range (e.g., `"yjs": "^13.0.0"`) and install a compatible version of `yjs`.
Use ESM import syntax: `import { IndexeddbPersistence } from 'y-indexeddb';`. Ensure your environment supports ESM or use a bundler that transpiles it correctly. If using TypeScript, check `tsconfig.json` for `moduleResolution` settings.Always `await` calls to `provider.clearData()` within an `async` function, or handle the Promise using `.then().catch()`.