Fix inefficient queryClient update when relay URL changes

This commit is contained in:
Alex Gleason committed 2025-10-16 18:42:35 -05:00
1 parent a974da9f88
commit 49abb22471
3 files changed
+4 -4

No files matched your search

+2 -2
View File
@@ -20,10 +20,10 @@ const NostrProvider: React.FC<NostrProviderProps> = (props) => {
// Use refs so the pool always has the latest data
const relayUrl = useRef<string>(config.relayUrl);
// Update refs when config changes
// Invalidate Nostr queries when relayUrl changes
useEffect(() => {
relayUrl.current = config.relayUrl;
queryClient.resetQueries();
queryClient.invalidateQueries({ queryKey: ['nostr'] });
}, [config.relayUrl, queryClient]);
// Initialize NPool only once
+1 -1
View File
@@ -6,7 +6,7 @@ export function useComments(root: NostrEvent | URL, limit?: number) {
const { nostr } = useNostr();
return useQuery({
queryKey: ['comments', root instanceof URL ? root.toString() : root.id, limit],
queryKey: ['nostr', 'comments', root instanceof URL ? root.toString() : root.id, limit],
queryFn: async (c) => {
const filter: NostrFilter = { kinds: [1111] };
+1 -1
View File
@@ -15,7 +15,7 @@ export function useLoggedInAccounts() {
const { logins, setLogin, removeLogin } = useNostrLogin();
const { data: authors = [] } = useQuery({
queryKey: ['logins', logins.map((l) => l.id).join(';')],
queryKey: ['nostr', 'logins', logins.map((l) => l.id).join(';')],
queryFn: async ({ signal }) => {
const events = await nostr.query(
[{ kinds: [0], authors: logins.map((l) => l.pubkey) }],