useReq() caches an empty result when no relays are configured, so no REQ is sent once they arrive
- Ngôn ngữ chính
- TypeScript
- Star
- 29
- Fork
- 3
- Merge trung bình
- 3 giờ 5 phút
- Pull request đã merge (30 ngày)
- 11
Mô tả
`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.
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- typescript
- Lĩnh vực
- frontend
- Loại issue
- Lỗi
- Độ khó
- 1/5
- Thời gian dự kiến
- Dưới một giờ
- Mức độ hoạt động
- Ít trao đổi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức phù hợp với người mới
- 78/100