Hacktoberfest 2026: as issues que os mantenedores marcaram para outubro, abertas e boas para iniciantes. Ver issues do Hacktoberfest

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

Aberta
#2,243 0 comentários 0 reações 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 1 dia

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
4/5
Tempo estimado
1-2 dias
Facilidade para iniciantes
48/100
Tipo de issue
Funcionalidade
Clareza
Claramente especificada
Status de atividade
Ativa
Stack de tecnologia
typescript
Domínio
backend

Direção de pesquisa

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.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

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.

Linguagem predominante
TypeScript
Estrelas
4k
Forks
277
Merge médio
18h 7min
PRs com merge (30d)
228

Preparar o ambiente

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de TanStack/db

Todas as issues de TanStack/db

Issues semelhantes

Mais issues de TypeScript

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.