TanStack / TanStack/db

The "recovery pattern" in the docs incompatible with live queries

Open
#923 3 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
3.9k
Forks
266
Avg merge
1d 4h
Merged PRs (30d)
55

Description

This recovery pattern in the docs:

Clean up collections in error states:


if (todoCollection.status === "error") {
  // Cleanup will stop sync and reset the collection
  await todoCollection.cleanup()
  
  // Collection will automatically restart on next access
  todoCollection.preload() // Or any other operation
}

https://tanstack.com/db/latest/docs/guides/error-handling#collection-cleanup-and-restart

Is incompatible with having an exiting live query on the collection, it will throw a warning and the live queries will not recover.

We should look how to ensure you can restart an errored collection without it breaking live queries - options:

  1. make the restart pattern softer with a new forceRestart that does one of:
  • internally truncates and resyncs - this should be compatible with live queries, but may not clear all state.
  • send a signal to also restart live queries that are attached to the collection.
  1. Chang the implementation such that a live query can be attached to a "cleaned up" collection that is then restarted and when it is would restart the live query. We can continue to emit the warning, but change it to indicate that the live query will not be updating as one of its sources is cleaned up.

Discussion on Discord: https://discord.com/channels/719702312431386674/1443598939331887238

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the collection cleanup and restart section in the linked error-handling documentation, then trace the cleanup warning and the live-query behavior it describes. Resolve which restart behavior is intended, and consider the work done when an errored collection can be restarted without leaving attached live queries unrecovered; the Discord discussion provides additional context.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
data
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.