Skip to content

[PowerSync]: Replacing optimistic state after insert #900

@Nick-Motion

Description

@Nick-Motion
  • [ 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:

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions