N-003
Local-First with Dexie
19 Apr 2026 · react, nextjs
This note as an agent skill: dexie in phucbm/skills.
Shell
A client app of mine keeps its data in the browser, in IndexedDB, through Dexie. It is a lot more room than localStorage (gigabytes instead of about 5 MB), queries are async, and useLiveQuery re-renders a component whenever the table it read changes, so there is no state library in between.
What I'd tell myself
- Schema versions only go up, and the old ones stay. A user who last opened the app three versions ago runs every upgrade in order. Delete version 1 from the code and their data has nowhere to come from.
- Only index what you filter or sort on. Everything else is stored anyway; indexes only slow the writes.
useLiveQuerystarts withundefined. That is the loading state, not an empty list.- It never runs on the server. IndexedDB is a browser API, so every component that touches the database is a client component, and nothing in a server component or
generateStaticParamscan read it.