akiomik / akiomik/nosvelte

useReq() writes to the query cache from a subscription with no liveness guard

Aperta
#87 1 commento 0 reazioni 0 assegnatari Vedi su GitHub
bug
Lingua principale
TypeScript
Stelle
29
Fork
3
Merge medio
3h 5m
PR unite (30g)
11

Descrizione

Once the query has settled, every subsequent event is written straight into the
cache from the subscription callback (`src/lib/stores/useReq.ts:60-62`):

```ts
if (fulfilled) {
queryClient.setQueryData(queryKey, v);
}
```

Nothing checks that the query still exists, that this subscription is still the
current one, or that anything is still observing.

- Each write refreshes `dataUpdatedAt`, so a query fed by a live subscription never
becomes stale.
- A subscription that outlives its consumers keeps writing — and `setQueryData` on a
garbage-collected key **recreates the cache entry**.
- Two live subscriptions on the same key (a retry, a refetch, or a leaked forward
req) each carry independent `scan` state and race to write different
accumulations to the same key, so `.data` flickers between them.

Related to #61, which is about the subscription outliving its consumer in the first
place; this is about the write path having no guard of its own.

Determined by code reading.

## Direction

Writes should go through something that owns the subscription's lifetime, so that a
subscription which is no longer current cannot reach the cache.

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.