-
Notifications
You must be signed in to change notification settings - Fork 130
Open
Description
- [ X] I've validated the bug against the latest version of DB packages
Describe the bug
When using powersync-db-collection, I wish to create a model with a temporary id, awaiting that mutation, then return the server-confirmed model result from my create method - entailing "swapping" the optimistic model for the confirmed model.
However, this is not possible for two reasons:
await tx.isPersisted.promiseresolves when the mutation resolves, not when the data has been synced via Powersync.- Similar to the problem described in usePacedMutation: No way to sync/clear mutations store after optimistic insert with server-generated IDs #893 - once the data is synced, there is no mechanism to replace optimistic data. So the temporary model remains alongside the confirmed.
Current Behavior
const tx = todosCollection.insert({
id: tempId,
name,
})
await tx.isPersisted.promise
// Problem: Resolved without confirmed data yet in client
// If there were, we could use view-key mapping to swap out optimistic data for real, described here: https://tanstack.com/db/latest/docs/guides/mutations#solution-3-maintain-a-view-key-mappingExpected behavior
There should be a way to await syncing of the confirmed data, and to swap out optimistic data for confirmed.
kobiebotha
Metadata
Metadata
Assignees
Labels
No labels