From fe172606d6a0347374e3013d088b644597bd5b58 Mon Sep 17 00:00:00 2001 From: ButtercupRoberts Date: Tue, 10 Nov 2026 23:14:55 +0000 Subject: [PATCH 1/3] =?UTF-8?q?fix(zaplytics):=20member=20avatars=20never?= =?UTF-8?q?=20loaded=20=E2=80=94=20'author'=20queryKey=20collides=20with?= =?UTF-8?q?=20useAuthor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit useMemberProfiles and useAuthor both cache under ['author', pubkey] but return different shapes ({name,picture} vs {event,metadata}). Whichever resolved first owned the slot; when useAuthor won, member nodes read 'picture' off the wrong shape and always rendered plain circles. --- src/components/zaplytics/ContributorNetworkGraph.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/components/zaplytics/ContributorNetworkGraph.tsx b/src/components/zaplytics/ContributorNetworkGraph.tsx index 1f3d3b61..e2836571 100644 --- a/src/components/zaplytics/ContributorNetworkGraph.tsx +++ b/src/components/zaplytics/ContributorNetworkGraph.tsx @@ -264,7 +264,10 @@ function useMemberProfiles(pubkeys: string[]): Map ({ - queryKey: ['author', pubkey], + // Must NOT share 'author' with useAuthor — that hook caches + // {event, metadata} under the same key and would poison this + // lookup with the wrong shape (member avatars never resolved). + queryKey: ['member-profile', pubkey], queryFn: async ({ signal }: { signal: AbortSignal }) => { if (!pubkey) return null; let [event] = await queryWithNip65Fanout( From 1dc54070adca455a7b4be242f0509729d074b44d Mon Sep 17 00:00:00 2001 From: ButtercupRoberts Date: Tue, 10 Nov 2026 23:31:40 +0000 Subject: [PATCH 2/3] fix(zaplytics): invalidate member-profile on edit; reuse author cache + discovery relays MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - EditProfileForm now invalidates ['member-profile', pubkey] alongside 'author' — edited avatars stayed stale for up to 5min in the graph - useMemberProfiles reads the cached useAuthor result first (avoids duplicate fetches vs the member table) and fans out to the same fallback discovery relays useAuthor uses --- src/components/EditProfileForm.tsx | 3 +++ .../zaplytics/ContributorNetworkGraph.tsx | 14 +++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/components/EditProfileForm.tsx b/src/components/EditProfileForm.tsx index 30ce446c..ebb7cd23 100644 --- a/src/components/EditProfileForm.tsx +++ b/src/components/EditProfileForm.tsx @@ -111,6 +111,9 @@ export const EditProfileForm: React.FC = () => { // Invalidate queries to refresh the data queryClient.invalidateQueries({ queryKey: ['logins'] }); queryClient.invalidateQueries({ queryKey: ['author', user.pubkey] }); + // The contributor graph caches member profiles under its own key — + // drop it too or the edited avatar stays stale on next graph mount. + queryClient.invalidateQueries({ queryKey: ['member-profile', user.pubkey] }); toast({ title: 'Success', diff --git a/src/components/zaplytics/ContributorNetworkGraph.tsx b/src/components/zaplytics/ContributorNetworkGraph.tsx index e2836571..492177ce 100644 --- a/src/components/zaplytics/ContributorNetworkGraph.tsx +++ b/src/components/zaplytics/ContributorNetworkGraph.tsx @@ -1,12 +1,12 @@ import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; import { Skeleton } from '@/components/ui/skeleton'; import { useState, useMemo } from 'react'; -import { useQueries } from '@tanstack/react-query'; +import { useQueries, useQueryClient } from '@tanstack/react-query'; import type { MemberStats } from '@/hooks/useCommunityZapStats'; import { formatSats } from '@/lib/zaplytics/utils'; import { useAppContext } from '@/hooks/useAppContext'; import { useNostr } from '@nostrify/react'; -import { queryWithNip65Fanout, getNip65ReadRelays } from '@/lib/queryRelays'; +import { queryWithNip65Fanout, getNip65ReadRelays, FALLBACK_DISCOVERY_RELAYS } from '@/lib/queryRelays'; import { NSchema as n } from '@nostrify/nostrify'; interface ContributorNetworkGraphProps { @@ -260,7 +260,11 @@ export function ContributorNetworkGraph({ members, isLoading }: ContributorNetwo function useMemberProfiles(pubkeys: string[]): Map { const { nostr } = useNostr(); const { config } = useAppContext(); + const queryClient = useQueryClient(); const nip65ReadRelays = getNip65ReadRelays(config.relayMetadata); + // Match useAuthor's coverage: member profiles may live only on the + // well-known discovery relays, not the current user's read set. + const profileRelays = [...new Set([...nip65ReadRelays, ...FALLBACK_DISCOVERY_RELAYS])]; const queries = useQueries({ queries: pubkeys.map((pubkey) => ({ @@ -270,10 +274,14 @@ function useMemberProfiles(pubkeys: string[]): Map { if (!pubkey) return null; + // Reuse a cached useAuthor result instead of refetching — the + // member table already loads the same profiles. + const cached = queryClient.getQueryData<{ metadata?: { name?: string; display_name?: string; picture?: string } }>(['author', pubkey]); + if (cached?.metadata) return cached.metadata; let [event] = await queryWithNip65Fanout( nostr, [{ kinds: [0], authors: [pubkey], limit: 1 }], - nip65ReadRelays, + profileRelays, AbortSignal.any([signal, AbortSignal.timeout(1500)]), ); if (!event) { From 240a171c2df644078bbb3fdeca5bcc9d4ca97221 Mon Sep 17 00:00:00 2001 From: ButtercupRoberts Date: Tue, 10 Nov 2026 23:36:50 +0000 Subject: [PATCH 3/3] fix(zaplytics): skip invalidated author cache when reusing profiles MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit invalidateQueries marks data stale but getQueryData still returns the pre-invalidation copy — the graph could reuse an old avatar before the author query refetches. Check getQueryState().isInvalidated first. --- src/components/zaplytics/ContributorNetworkGraph.tsx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/components/zaplytics/ContributorNetworkGraph.tsx b/src/components/zaplytics/ContributorNetworkGraph.tsx index 492177ce..2bd6a400 100644 --- a/src/components/zaplytics/ContributorNetworkGraph.tsx +++ b/src/components/zaplytics/ContributorNetworkGraph.tsx @@ -275,8 +275,12 @@ function useMemberProfiles(pubkeys: string[]): Map { if (!pubkey) return null; // Reuse a cached useAuthor result instead of refetching — the - // member table already loads the same profiles. - const cached = queryClient.getQueryData<{ metadata?: { name?: string; display_name?: string; picture?: string } }>(['author', pubkey]); + // member table already loads the same profiles. Skip it when the + // entry was invalidated (e.g. profile edit): getQueryData still + // returns the pre-invalidation data while it waits to refetch. + const cacheState = queryClient.getQueryState(['author', pubkey]); + const cached = cacheState?.isInvalidated ? undefined + : queryClient.getQueryData<{ metadata?: { name?: string; display_name?: string; picture?: string } }>(['author', pubkey]); if (cached?.metadata) return cached.metadata; let [event] = await queryWithNip65Fanout( nostr,