TanStack / TanStack/db

Data not persisted locally when using @tanstack/browser-db-sqlite-persistence + @tanstack/electric-db-collection doesn't persists data locally

Open
#1,456 0 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
3.9k
Forks
266
Avg merge
1d 4h
Merged PRs (30d)
55

Description

[x] I've validated the bug against the latest version of DB packages

Describe the bug

When adding a bale, the item is correctly stored in memory, but after refreshing the page the data disappears.
@tanstack/browser-db-sqlite-persistence does not seem to persist the collection.

export const baleCollection = createCollection(
  persistedCollectionOptions<Bale, string | number>({
    ...electricCollectionOptions({
      id: "bales",
      shapeOptions: {
        url: getElectricUrl(),
        params: { table: "bale" },
      },
      getKey: (i) => i.id,
      async onInsert({ transaction, collection }) {
        const newItem = transaction.mutations[0].modified;
        const txid = await createBale(newItem);
        await collection.utils.awaitTxId(txid);
      },
    }),
    persistence,
    schemaVersion: 1,
  })
);

To Reproduce

Steps to reproduce:

  1. Add an item
  2. Refresh the page
  3. The previously added data is gone

Expected behavior

Data should persist across page reloads when using SQLite persistence.

Desktop (please complete the following information):

  • OS: Windows 11
  • Browser: Edge
  • Version: 146.0.3856.97

Smartphone (please complete the following information):

N/A

Additional context

  • @tanstack/browser-db-sqlite-persistence: 0.1.6
  • @tanstack/electric-db-collection: 0.3.0
  • @tanstack/react-db: 0.1.80

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the issue with the shown persistedCollectionOptions configuration and the listed package versions. Trace how @tanstack/browser-db-sqlite-persistence is initialized and used with @tanstack/electric-db-collection, then verify the collection after a page reload. Done means an inserted bale remains available after refreshing the page.

Written by the indexing model from the issue text.

Assessment

Tech stack
sqlite, typescript
Domain
database
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.