fix: dedupe filtering for non-optimistic mutations#715
fix: dedupe filtering for non-optimistic mutations#715KyleAMathews merged 3 commits intoTanStack:mainfrom
Conversation
🦋 Changeset detectedLatest commit: cac67f7 The changes in this PR will be included in the next version bump. This PR includes changesets to release 12 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Can you share your code that wasn't working before this fix? |
It works for all clients that didn't originate the transaction. For the client that initiates the transaction, the local collection is not updated. export const chatThreadsCollection = createCollection(
electricCollectionOptions({
id: "chat-threads",
shapeOptions: { ... },
getKey: (row) => row.id,
schema: ChatThreadSchema,
onInsert: async ({ transaction }) => {
const { modified } = transaction.mutations[0]!;
const { id: _id, created_at: _c, updated_at: _u, ...payload } = modified;
const response = await api.chat.threads.create(payload);
return { txid: response.txid };
},
onUpdate: async ({ transaction }) => {
const { original, changes } = transaction.mutations[0]!;
const { id: _id, created_at: _c, updated_at: _u, ...payload } = changes;
const response = await api.chat.threads.update(original.id, payload);
return { txid: response.txid };
},
onDelete: async ({ transaction }) => {
const { original } = transaction.mutations[0]!;
const response = await api.chat.threads.destroy(original.id);
return { txid: response.txid };
},
})
);const tx = chatThreadsCollection.delete(id, { optimistic: false });
await tx.isPersisted.promise; |
|
Even after the synced tx comes back? It seems like you might have a txid matching issue perhaps? https://tanstack.com/db/latest/docs/collections/electric-collection#debugging |
|
I don't believe I do. From the console logs immediately following delete: My syncing is working everywhere else. It's only in this instance where I'm trying to use non-optimistic for a delete that it is broken. |
More templates
@tanstack/angular-db
@tanstack/db
@tanstack/db-ivm
@tanstack/electric-db-collection
@tanstack/query-db-collection
@tanstack/react-db
@tanstack/rxdb-db-collection
@tanstack/solid-db
@tanstack/svelte-db
@tanstack/trailbase-db-collection
@tanstack/vue-db
commit: |
|
Ah ok I see. This PR prevents non-optimistic mutations from being added to completedOptimisticOps. The synced data is coming back and the optimistic mutations are being dropped but the collection thinks nothing has changed so doesn't emit anything but it has because it wasn't optimistic. |
KyleAMathews
left a comment
There was a problem hiding this comment.
Thanks for the fix!
|
@KyleAMathews thanks for the quick merge 🙏 |
|
🎉 This PR has been released! Thank you for your contribution! |
🎯 Changes
Fix
commitPendingTransactionsso that completed, non-optimistic mutations no longer suppress matching synced events, allowing the initiating client to observe the server-sourced mutation.✅ Checklist
pnpm test:pr.🚀 Release Impact