Hacktoberfest 2026 : les issues que les mainteneurs ont marquées pour octobre, ouvertes et accessibles aux débutants. Parcourir les issues Hacktoberfest

Deferred live queries: let the sync adapter report an already-held subset (isSubsetLoaded) so a remounted page renders on its first frame

Ouverte
#2,243 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é
4/5
Temps estimé
1-2 jours
Accessibilité débutants
48/100
Type d'issue
Fonctionnalité
Clarté
Clairement spécifiée
Activité
Active
Stack technique
typescript
Domaine
backend

Piste de recherche

Read types.ts, collection/sync.ts, and collection/subscription.ts, focusing on CollectionSubscription.startSubsetDemand and the deferred acquisition path. First inspect the existing subset loading tests and run the relevant @tanstack/db tests. Done means the optional hook publishes rows for an already-held deferred subset while preserving the three stated loading and acquisition cases.

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

Description

Since #2060, a live query with no subscriber or preload yet keeps its on-demand source demands detached. An ordered window over such a source stays unpublished until its acquisitions settle. That's the right default: render work starts no provider work.

It also means a page that mounts again (back navigation, a tab switch, a route that unmounts and remounts) draws loading on its first frame, even when the source still holds every row of that window. The supported way around it is to preload() the same live query in a route loader. That only works when the loader can name the exact query. When the query depends on who is viewing, on settings, or on other queries, the first frame is empty, the page renders short, and the browser's scroll restoration clamps to the top.

The sync adapter often knows that a subset is already held. Its loadSubset would answer true at once, but core can't ask without breaking #2060's rule.

Proposal: an optional, side-effect-free hook on the sync result:

type SyncConfigRes = {
  loadSubset?: LoadSubsetFn
  unloadSubset?: UnloadSubsetFn
  /**
   * Whether the Collection already holds every row of the subset `options`
   * names, so `loadSubset` would answer `true` at once. A local check: no
   * provider work, no state change.
   */
  isSubsetLoaded?: (options: LoadSubsetOptions) => boolean
}

In CollectionSubscription.startSubsetDemand, the deferred on-demand branch still records the demand as detached, exactly as now. When isSubsetLoaded(requestOptions) returns true, it returns true instead of the pending initial result, so the window publishes from rows already installed. Acquisition still starts on resumeDeferredAcquisition(), so provider sync, revalidation and live updates are unchanged. Without the hook, nothing changes.

We have this implemented on 0.15.2: about 30 lines across types.ts, collection/sync.ts and collection/subscription.ts. A test covers three cases:

  • a deferred window over a held subset is ready with its rows before it subscribes, and still calls loadSubset after subscribing;
  • without the hook, it stays loading;
  • for a subset that isn't held, it stays loading.

The full @tanstack/db suite passes. Our InstantDB adapter answers the hook from its ready subscriptions and held prefixes, and it fixed back-navigation scroll restoration for us. Happy to open a PR.

Langage dominant
TypeScript
Étoiles
3.9k
Forks
277
Merge moyen
18 h 7 min
PR mergées (30 j)
228

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.