useReq() caches an empty result when no relays are configured, so no REQ is sent once they arrive
- Dominant language
- TypeScript
- Stars
- 29
- Forks
- 3
- Avg merge
- 3h 5m
- Merged PRs (30d)
- 11
Description
`useReq()` returns early when `rxNostr.getDefaultRelays()` is empty, and writes the
hook's `initData` into the query cache on the way out (`src/lib/stores/useReq.ts:25-33`):
```ts
if (Object.keys(rxNostr.getDefaultRelays()).length === 0) {
queryClient.setQueryData(queryKey, initData);
```
For every list hook (`initData: []` — `useEventList`, `useUniqueEventList`,
`useMetadataList`, `useUserArticleList`, `useUserReactionList`, `useUserTextList`)
this stores `[]` with `status: 'success'` and `dataUpdatedAt = now`. With
`staleTime: 1000 * 60` (`src/lib/components/NostrApp.svelte:23`) that entry is not
stale, so when relays become available and the hook re-runs, the new observer is
served from cache and **`queryFn` is never called**.
Verified on `main` (609f8ed) against the mock relay harness: after configuring a
real relay and re-invoking `useUniqueEventList` with the same key, the relay
received zero messages, `$data === []` and `$status === 'success'`. The component
renders its `nodata` slot for a full minute with no request in flight.
This is reachable in any app that obtains relays asynchronously — NIP-07,
localStorage, user settings, or simply `` on first paint.
Every such app shows "not found" everywhere and sends no REQ.
## Corollary
For the single-event hooks `initData` is `undefined`, and
`setQueryData(key, undefined)` is a no-op in query-core — it does not even create a
cache entry (verified: `getQueryCache().find(...)` returned `undefined`). So the
same line is simultaneously dead code and a data-corruption source.
## Direction
Removing the `setQueryData()` call fixes both halves: the singular hooks lose
nothing, and the list hooks stop caching a result they never fetched. The early
return itself can keep returning the static stores.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start in src/lib/stores/useReq.ts around lines 25-33, where the early return for empty rxNostr.getDefaultRelays() calls queryClient.setQueryData(queryKey, initData). Compare with staleTime in src/lib/components/NostrApp.svelte:23. Done means the empty-relay path no longer caches unfetched initData, while still returning the static stores.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 78/100