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 <noreply@anthropic.com>
This commit is contained in:
Jure
2026-03-08 19:23:51 +01:00
parent b465ad03a3
commit a8a3581f9a
2 changed files with 7 additions and 1 deletions

View File

@@ -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,

View File

@@ -4,6 +4,11 @@ import { fetchProfile } from "../lib/nostr";
const profileCache = new Map<string, any>();
const pendingRequests = new Map<string, Promise<any>>();
export function invalidateProfileCache(pubkey: string) {
profileCache.delete(pubkey);
pendingRequests.delete(pubkey);
}
export function useProfile(pubkey: string) {
const [profile, setProfile] = useState<any>(profileCache.get(pubkey) ?? null);