From 49abb22471743818a05add1b00023afb59201617 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Thu, 16 Oct 2025 18:42:35 -0500 Subject: [PATCH] Fix inefficient queryClient update when relay URL changes --- src/components/NostrProvider.tsx | 4 ++-- src/hooks/useComments.ts | 2 +- src/hooks/useLoggedInAccounts.ts | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/components/NostrProvider.tsx b/src/components/NostrProvider.tsx index 6d74597..5f94ef9 100644 --- a/src/components/NostrProvider.tsx +++ b/src/components/NostrProvider.tsx @@ -20,10 +20,10 @@ const NostrProvider: React.FC = (props) => { // Use refs so the pool always has the latest data const relayUrl = useRef(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 diff --git a/src/hooks/useComments.ts b/src/hooks/useComments.ts index 49922c5..5fdf42b 100644 --- a/src/hooks/useComments.ts +++ b/src/hooks/useComments.ts @@ -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] }; diff --git a/src/hooks/useLoggedInAccounts.ts b/src/hooks/useLoggedInAccounts.ts index bffdbab..e1b1d8c 100644 --- a/src/hooks/useLoggedInAccounts.ts +++ b/src/hooks/useLoggedInAccounts.ts @@ -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) }],