Repository navigation
0022 patch expo sqlite web
Status: accepted · Implementation: done · Date: 2026-11-18
From LibreLifts ADR 0036; the patch is the one written there, for expo-sqlite 58.0.18. It has not been reported to Expo; sending a report is the maintainer's call. As built, 2026-11-18: the patch is applied on install, unchanged from LibreLifts, and the web build opens its database. The burst of writes it exists for has not been shown again here, because there are no screens to log with yet, so this stays planned. Shown again here on 2026-11-18, in Chromium: 300 sets added to one workout in under four seconds, each a transaction of its own followed by the screen reading the workout again, with no error and 301 rows on screen; then the workout was discarded, which marks every one of them. The page was not run without the patch for comparison.
The app reads and writes its database with synchronous calls
(0018). In the browser, expo-sqlite runs SQLite in a worker,
and each synchronous call makes a new one-megabyte shared buffer for the answer. None of
those buffers is freed until the page and the worker are both idle.
LibreLifts found what follows from that. A burst of calls runs the page out of memory. The call that fails is often in the middle of a transaction, and the rollback fails for the same reason. The transaction then stays open, every later one is refused, and the app shows an error until the page is reloaded. iOS and Android are not affected.
LibreBars keeps the web build (0007), so it has the same problem.
-
expo-sqliteis patched with pnpm'spatchedDependenciesso that synchronous calls in the browser share one result buffer and one lock. The patch ispatches/expo-sqlite@58.0.18.patchand changes one file,web/WorkerChannel.ts. - It is safe because calls happen one at a time and the answer is copied out of the buffer before the call returns. If a call times out, the buffers are dropped and the next call gets new ones.
- The app also batches its writes on every platform: several rows of one table go in one statement, with their outbox notes in another.
-
The patch is tied to the exact version. Updating
expo-sqlitemeans checking whether the patch is still needed and making it again if it is.
- A burst of writes does not break the web build. In LibreLifts this was tested with 150 workouts logged in one go and 2,550 changes sent afterwards; it has to be shown again here.
- The project carries a patch to a dependency. pnpm fails the install if the patch no longer applies, so it cannot be dropped silently.
-
expo-sqlitecannot be updated without looking at the patch. - This is made for the web build alone, against the rule that nothing is. It is allowed because without it the web build loses data. It goes when the web build goes.
Generated from docs/ on dev. Edit the docs there; changes made on the wiki are overwritten.
- Development
- Workflow
-
Decisions
- 0001 Decisions are recorded
- 0002 Apache License 2.0
- 0003 Changes land on dev by fast-forward; main is the last release
- 0004 Conventional Commits, Keep a Changelog and Semantic Versioning
- 0005 docs/ is for developers and is mirrored to the wiki
- 0006 LibreBars is a free workout log for calisthenics
- 0007 The tracker is an iOS and Android app; its web build stays until the store release
- 0008 LibreBars is an app and a crowd-sourced open database
- 0009 The database is ODbL, media is CC BY-SA, and neither can be closed later
- 0010 A hosted API with a free tier is the paid product
- 0011 The workspace is app, web and api, with engine, ui, data and contracts
- 0012 The engine is small pure functions, in the style of date-fns
- 0013 Web and app share a Tailwind theme, not components
- 0014 Postgres is the source of truth for all data
- 0015 The API is Fastify, and it owns LibreBars accounts
- 0016 Every install is a guest account, made in the background
- 0017 Accounts use Better Auth
- 0018 The on-device database is SQLite with Drizzle, on every platform
- 0019 Sync is our own push and pull
- 0020 The app says it backs up, and backup can be turned off
- 0021 Postgres 18, run with Docker Compose and tested on two databases
- 0022 expo-sqlite is patched so the web build reuses one buffer
- 0023 Seed data is TypeScript modules in packages/data, with permanent ids
- 0024 The first tables
- 0025 One TanStack Start app is the website, on GitHub Pages
- 0026 The catalog reaches the app as a snapshot plus updates, and the website through the API
- 0027 The app's first components are its own