Skip to content

Race between transactions + query refresh when coming online #1323

@Hawxy

Description

@Hawxy
  • I've validated the bug against the latest version of DB packages

Describe the bug
When combining offline transactions with queryCollection and the refetchOnReconnect option is enabled, there's a race between the immediate refetch of server state and the pending transactions being sent to the server. This can result in the state reverting to the pre-mutation state until the next stale time is reached.

This can be worked around by force-refreshing after mutations are applied, but on slow network connections or API operations this could result in UI "blips" where the state reverts for a few moments before being updated. This also results in redundant queries being made and simply isn't useful behaviour.

To Reproduce
Steps to reproduce the behavior:

  1. Configure @tanstack/offline-transactions + @tanstack/query-db-collection.
  2. Setup a query function + offline mutation.
  3. Go offline and queue a mutation.
  4. Come back online, the collection will fetch immediately and reset the DB state before transactions are applied.

Expected behavior
The query should be blocked from refetching until pending transactions have been applied.

Screenshots

The red line is when the system is offline, the green is immediately after coming online. stream is the queryFn and is called immediately, and then called again manually after a mutation to the correct the state.

Image

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