[PowerSync]: Replacing optimistic state after insert
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 3.9k
- Forks
- 266
- Avg merge
- 1d 4h
- Merged PRs (30d)
- 55
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 https://github.com/TanStack/db/issues/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-mapping
Expected behavior
There should be a way to await syncing of the confirmed data, and to swap out optimistic data for confirmed.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No file or test is named. Start with the powersync-db-collection insert flow and the tx.isPersisted.promise behavior described in the report, then trace when confirmed data reaches the client. Done should cover awaiting synced data and replacing the temporary model without leaving a duplicate.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- databases, frontend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100