Skip to content

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

@Altro31

Description

@Altro31

[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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions