feat: handle delete-insert in transaction merging #1068
main fromrefs/pull/1068/head·opened 🎯 Changes#
So related to the whole longer lived editing session concept, running into delete and the insert issue on pending mutation. Basically if user deletes something in our editor, we tx.mutate and delete the record. Then if the user cmd+z to undo in our editor, we reverse the operation and insert the record that was just deleted (on same tx, it has not been committed yet).
This pattern results in the Uncaught Error: Unhandled mutation combination: delete-insert error.
This PR adds handling for delete-insert pattern.
✅ Checklist#
- I have followed the steps in the Contributing guide.
- I have tested this code locally with
pnpm test:pr.
🚀 Release Impact#
- This change affects published code, and I have generated a changeset.
- This change is docs/CI/dev-only (no release).
- 1
More templates
@tanstack/angular-db
npm i https://pkg.pr.new/@tanstack/angular-db@1068@tanstack/db
npm i https://pkg.pr.new/@tanstack/db@1068@tanstack/db-ivm
npm i https://pkg.pr.new/@tanstack/db-ivm@1068@tanstack/electric-db-collection
npm i https://pkg.pr.new/@tanstack/electric-db-collection@1068@tanstack/offline-transactions
npm i https://pkg.pr.new/@tanstack/offline-transactions@1068@tanstack/powersync-db-collection
npm i https://pkg.pr.new/@tanstack/powersync-db-collection@1068@tanstack/query-db-collection
npm i https://pkg.pr.new/@tanstack/query-db-collection@1068@tanstack/react-db
npm i https://pkg.pr.new/@tanstack/react-db@1068@tanstack/rxdb-db-collection
npm i https://pkg.pr.new/@tanstack/rxdb-db-collection@1068@tanstack/solid-db
npm i https://pkg.pr.new/@tanstack/solid-db@1068@tanstack/svelte-db
npm i https://pkg.pr.new/@tanstack/svelte-db@1068@tanstack/trailbase-db-collection
npm i https://pkg.pr.new/@tanstack/trailbase-db-collection@1068@tanstack/vue-db
npm i https://pkg.pr.new/@tanstack/vue-db@1068commit:
1cf246cTests failing with:
error Dependency @tanstack/query-db-collection has multiple versions defined in the workspace. multiple-dependency-versions error Dependency @tanstack/react-db has multiple versions defined in the workspace. multiple-dependency-versionsBut only in CI - works on my local machine. Let me know if there's something I should do to resolve them!
Hey @marbemac
This looks ok to me, but @KyleAMathews should cast his eyes over it as he spent some time working through the logic around handing these overlapping mutations in a transaction.
CI does a soft merge on main when it runs, and it was main that was broken (due to a new check being added)... CI is now green.
hi team, just following up here to see if this is still something ya'll might consider?
I ran into the same issue today.
transaction.ts says:
* Note: (delete, update) and (delete, insert) should never occur as the collection * layer prevents operations on deleted items within the same transaction.But I can confirm: it is possible to delete first and insert afterwards in the same tx, but then you get this error "Unhandled mutation combination: delete-insert"
Closing as superseded by merged PR #1835, which fixes same-key delete-then-insert reduction with broader authoritative, repeated, and concurrent coverage while preserving the original contributor credit.
KyleAMathews(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
🦋 Changeset detected#
Latest commit: 1cf246c8554692bbe4208ce3b9b30ddd7c2b3fdc
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