Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

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

Aperta
#2,243 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
1-2 giorni
Idoneità per principianti
48/100
Tipo di issue
Funzionalità
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
typescript
Ambito
backend

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
TypeScript
Stelle
4k
Fork
277
Merge medio
17h 40m
PR unite (30g)
223

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di TanStack/db

Tutte le issue di TanStack/db

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.