From a8a3581f9ab7e5d3b8c6ac29da19ca3e8e3e23eb Mon Sep 17 00:00:00 2001 From: Jure <44338+hoornet@users.noreply.github.com> Date: Sun, 8 Mar 2026 19:23:51 +0100 Subject: [PATCH] Fix profile cache invalidation after editing Invalidate the in-memory profile cache for the user's pubkey after publishing a new kind 0 event, so the updated profile reflects immediately. Co-Authored-By: Claude Sonnet 4.6 --- src/components/profile/ProfileView.tsx | 3 ++- src/hooks/useProfile.ts | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/components/profile/ProfileView.tsx b/src/components/profile/ProfileView.tsx index b044f66..e3f716f 100644 --- a/src/components/profile/ProfileView.tsx +++ b/src/components/profile/ProfileView.tsx @@ -2,7 +2,7 @@ import { useEffect, useState } from "react"; import { NDKEvent } from "@nostr-dev-kit/ndk"; import { useUIStore } from "../../stores/ui"; import { useUserStore } from "../../stores/user"; -import { useProfile } from "../../hooks/useProfile"; +import { useProfile, invalidateProfileCache } from "../../hooks/useProfile"; import { fetchUserNotes, publishProfile } from "../../lib/nostr"; import { shortenPubkey } from "../../lib/utils"; import { NoteCard } from "../feed/NoteCard"; @@ -25,6 +25,7 @@ function EditProfileForm({ pubkey, onSaved }: { pubkey: string; onSaved: () => v setSaving(true); setError(null); try { + invalidateProfileCache(pubkey); await publishProfile({ name: name.trim() || undefined, display_name: displayName.trim() || undefined, diff --git a/src/hooks/useProfile.ts b/src/hooks/useProfile.ts index e85713e..45df829 100644 --- a/src/hooks/useProfile.ts +++ b/src/hooks/useProfile.ts @@ -4,6 +4,11 @@ import { fetchProfile } from "../lib/nostr"; const profileCache = new Map(); const pendingRequests = new Map>(); +export function invalidateProfileCache(pubkey: string) { + profileCache.delete(pubkey); + pendingRequests.delete(pubkey); +} + export function useProfile(pubkey: string) { const [profile, setProfile] = useState(profileCache.get(pubkey) ?? null);