Skip to content

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

@samwillis

Description

@samwillis

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

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