akiomik / akiomik/nosvelte

useReq() caches an empty result when no relays are configured, so no REQ is sent once they arrive

Đang mở
#74 0 bình luận 0 reaction 0 người được giao Xem trên GitHub
bug
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

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.