TanStackT
TanStack4w ago
5 replies
awake-maroon

[SOLVED] Offline mutations: Should insert+delete operations cancel each other out in the outbox?

I'm experimenting offline transactions.
This test repo is my sandbox. https://github.com/Toba-bonjour/Tanstack-DB-Issue

Step 0 - Before all:
- Empty outbox
- UI clear

Step 1 - Browser is offline:
- Add a new todo (id 1766009089447)
- Outbox length: 1
[db4809cb-4e62-4a0d-984c-1a50fb795311]


Step 2:
- Delete newly added todo (id 1766009089447)
- Outbox length: 2
[ db4809cb-4e62-4a0d-984c-1a50fb795311, 5f5d8b47-e587-4c98-82d4-cb41104b132f ]
- Todo is removed, UI is clear

Step 3 - Browser comes online:
- addOneTodo endpoint is called and applies direct writes (upserting server item response)
- deleteOneTodo endpoint is called and applies direct writes (deleting using server id from response)
- Outbox length: 1
[5f5d8b47-e587-4c98-82d4-cb41104b132f]
- UI remains clear

From this point, the deleteOneTodo endpoint will retry until it definitively fails and is removed from the outbox.
Before being removed, here's the mutation lastError from the outbox (which seems coherent with the UI).

lastError: { name: "DeleteOperationItemNotFoundError", message: "Delete operation: Item with key '1766009089447' does not exist" }

Question: Would it be logical behavior to have an entirely cleared outbox after inserting and deleting the same item offline, instead of replaying both actions?

I could use removeFromOutbox() manually, but it's tedious to do so for every case like this.
GitHub
Contribute to Toba-bonjour/Tanstack-DB-Issue development by creating an account on GitHub.
GitHub - Toba-bonjour/Tanstack-DB-Issue
Was this page helpful?