network-first: an eager Collection that last synced to zero rows stays loading offline

Ouverte
#2,284 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 1 jour

Personne n'a encore pris cette issue.

Évaluation

Difficulté
5/5
Temps estimé
Plus d'une semaine
Accessibilité débutants
35/100
Type d'issue
Fonctionnalité
Clarté
Plutôt claire
Activité
Active
Stack technique
sqlite, typescript
Domaine
backend, database

Piste de recherche

Start with the persisted-readiness oracle at packages/db-sqlite-persistence-core/tests/persisted-readiness-oracle.test.ts and the readiness rules in docs/guides/sqlite-persistence.md. The issue calls for deciding what evidence makes an empty restore safe and which events invalidate it; review the linked discussions #2203 and #2263 for prior design context. Done means the law and its authority are stated, generated history reaches an empty completed restore, the parent fails, the change passes, and a hostile mutant still rejects a cold empty cache.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

Summary

With initialRender: { strategy: 'network-first' }, an eager persisted Collection whose last sync produced zero rows stays loading offline. It becomes ready only when the sync adapter answers. An offline app therefore cannot show "no rows" for a Collection that is truly empty.

This is documented, intended behavior today. The guide (docs/guides/sqlite-persistence.md, "These rules keep ready meaningful") says:

An empty restore waits for the network. The Collection stays loading until the sync adapter answers, so an empty list always means "no rows". A Collection that last synced to zero rows also waits, because the restore cannot tell the two cases apart.

This issue asks whether the law should change, and how.

The problem

An empty restore has two causes that the wrapper cannot tell apart:

  1. A cold cache that never synced. Showing it as ready and empty is wrong.
  2. A cache whose last completed sync produced zero rows. Showing it as ready and empty is correct.

To open the second case offline, the wrapper needs evidence that a sync completed and that the empty row set is that sync's result.

Earlier proposal

#2203 proposed an adapter capability, isPersistedSnapshotComplete, that certifies a completed full snapshot with durable row-set evidence. That PR also covered Electric's progressive mode. #2263 solved the progressive case with per-demand coverage and no new adapter API, so #2203 was closed. #2203 did not address the eager empty case separately, and #2263 left it out of scope.

Questions for a design

  • Can the wrapper record "a full sync completed in this cache generation" itself, as #2263 does for each demand, without a new adapter API? For example, record it when the adapter calls markReady() after a complete snapshot and the rows are durably committed.
  • Which events end that evidence? Candidates are a truncate, a snapshot transaction, a cache-generation rotation, and a schema reset.
  • Does an eager source's markReady() always mean a complete snapshot, or only for some adapters?

Expected evidence for a change

The persisted-readiness oracle (packages/db-sqlite-persistence-core/tests/persisted-readiness-oracle.test.ts) owns this law. A change needs a stated law and authority, a generated history that reaches an empty completed restore, RED on the parent, GREEN after the change, and a hostile mutant that opens a cold empty cache.

Related

  • #2202, fixed by #2263.
  • #2102, design of safe offline subset reuse.
  • #2203, closed.
Langage dominant
TypeScript
Étoiles
4k
Forks
277
Merge moyen
1 j 7 h
PR mergées (30 j)
172

Préparer son environnement

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de TanStack/db

Toutes les issues de TanStack/db

Issues similaires

Plus d'issues TypeScript

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.