Skip to content

Local-only persisted startup calls markReady after collection cleanup #1889

Description

@cucumber-sp

Versions

  • @tanstack/db-sqlite-persistence-core@0.2.23 (latest published)
  • @tanstack/db@0.9.2
  • Local-only persistedCollectionOptions (no upstream sync adapter)

Bug

createLoopbackSyncConfig() starts runtime.ensureStarted() asynchronously and calls params.markReady() in both its fulfillment and rejection callbacks. Its cleanup() calls runtime.cleanup() but does not invalidate those already-registered callbacks.

A deterministic sequence is:

  1. Create a local-only persisted collection with an adapter whose initial SQLite hydration/read is held on a deferred Promise.
  2. Start collection.preload().
  3. Call collection.cleanup() while the startup read is pending.
  4. Settle the read, either by resolving it or rejecting it.

The late callback calls markReady() on the cleaned collection. In our account-switch/logout path this produces InvalidCollectionStatusTransitionError (cleaned-up -> ready) and an unhandled rejection. The rejection branch also logs a stale startup warning after the collection has been disposed.

The published dist/esm/persisted.js path is the same in current main: createLoopbackSyncConfig calls params.markReady() after ensureStarted().then(...) and in .catch(...), while cleanup only calls runtime.cleanup() / runtime.clearSyncControls().

Expected: Cleanup invalidates both startup continuations; neither calls markReady() or logs an obsolete startup error after cleanup. A new collection/session can then start independently.

Workaround: We carry a small package patch with a cleanedUp flag set before runtime cleanup, checked in both startup outcomes. Related app-side tracking: https://github.com/digitalcontour/oreol-monorepo/issues/299.

This is distinct from #1576 (preload after cleanup) and from the sync-present readiness policy in #1659. PR #1853 addresses several persistence lifecycle failures, but its current createLoopbackSyncConfig diff does not appear to fence the late markReady() callback; the regression above would be useful alongside it.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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