Skip to content

electric-db-collection, sync breaks after change #399

Description

@burakcan

Hi, I'm having an issue with this collection. The setup is a pretty barebones. In this scenario:

  • There are A and B clients
  • A makes a change, B gets the update
  • A makes another (doesn't matter how many), B gets the update.
  • But if B makes a change after A made a change, then changes are not reflected on the client A.
  • This only happens with tanstack-db. If I use useShape from electric, it works normally.

My collection:

export const collectionsCollection = createCollection(
  electricCollectionOptions<Collection>({
    id: "collections",
    getKey: (row) => row.id,
    shapeOptions: {
      url: `${import.meta.env.VITE_API_URL}/api/sync/collections`,
      fetchClient: (input, init) =>
        fetch(input, {
          credentials: "include",
          ...init,
        }),
    },
    onInsert: async ({ transaction }) => {
      const { txId } = await ApiService.createCollection(
        transaction.mutations[0].modified
      );

      return { txid: txId };
    },
    onDelete: async ({ transaction }) => {
      const { txId } = await ApiService.deleteCollection(
        transaction.mutations[0].modified.id
      );

      return { txid: txId };
    },
    onUpdate: async ({ transaction }) => {
      const { txId } = await ApiService.updateCollection(
        transaction.mutations[0].modified
      );

      return { txid: txId };
    },
  })
);

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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