Skip to content

Multiple Persisted Collections Shared Db #1419

@ghardin1314

Description

@ghardin1314
  • I've validated the bug against the latest version of DB packages

Describe the bug
Trying out persisted collections that are synced from a server. When trying to use the same database + coordinator for multiple collections shows this error:

__root.tsx:72 Failed to persist wrapped sync transaction: OPFSWorkerRequestError: cannot start a transaction within a transaction
at createWorkerError (opfs-database.ts?v=b19eef35:27:10)
at Worker.onMessage (opfs-database.ts?v=b19eef35:91:27)

const database = await openBrowserWASQLiteOPFSDatabase({
    databaseName: `persisted-synced.sqlite`,
  });
  const coordinator = new BrowserCollectionCoordinator({
    dbName: `persisted-synced`,
  });

  // --- Todos collection ---
  const todosPersistence = createBrowserWASQLitePersistence<Todo, string>({
    database,
    coordinator,
  });
  const todosQueryOpts = queryCollectionOptions({
    ....
  });
  const todosCollection = createCollection({
    ...persistedCollectionOptions({
      ...todosQueryOpts,
      persistence: todosPersistence,
      schemaVersion: 2,
    }),
    schema: todoSchema,
  });

  // --- Projects collection ---
  const projectsPersistence = createBrowserWASQLitePersistence<
    Project,
    string
  >({
    database,
    coordinator,
  });
  const projectsQueryOpts = queryCollectionOptions({
    ...
  });
  const projectsCollection = createCollection({
    ...persistedCollectionOptions({
      ...projectsQueryOpts,
      persistence: projectsPersistence,
      schemaVersion: 1,
    }),
    schema: projectSchema,
  });

Using a separate database + coordinator for each collection seems to work fine

To Reproduce
ghardin1314/tdb-pwa@1d2c516

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: MacOs
  • Browser Brave
  • Version [e.g. 22]

Additional context
Add any other context about the problem here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions