akiomik / akiomik/nosvelte

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

未关闭 适合新手
#74 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
bug
主要语言
TypeScript
星标
29
派生
3
平均合并
3 小时 5 分钟
30 天内合并 PR
11

描述

`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.

贡献指南

这个仓库没有索引到贡献指南

调研方向

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.

由索引模型根据 Issue 内容生成。

评估

技术栈
typescript
领域
frontend
Issue 类型
缺陷
难度
1/5
预计耗时
1 小时以内
活跃度
冷清
描述清晰度
描述清楚
新手友好度
78/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。