Fix React error #31 crash from malformed Nostr profiles

Malformed profiles with non-string fields (e.g. nip05: {}) crashed
React's entire render tree in production. Add typeof guards and
profileName() utility across all components that render profile data.
Add ErrorBoundary in main.tsx to show crash details instead of blank screen.
This commit is contained in:
Jure
2026-04-01 12:09:57 +02:00
parent 5a9d387923
commit c1029327e7
16 changed files with 92 additions and 52 deletions

View File

@@ -5,7 +5,7 @@ import { useUIStore } from "../../stores/ui";
import { useNotificationsStore } from "../../stores/notifications";
import { fetchDMConversations, fetchDMThread, sendDM, decryptDM, getNDK } from "../../lib/nostr";
import { useProfile } from "../../hooks/useProfile";
import { timeAgo, shortenPubkey } from "../../lib/utils";
import { timeAgo, shortenPubkey, profileName } from "../../lib/utils";
// ── Helpers ──────────────────────────────────────────────────────────────────
@@ -45,7 +45,7 @@ function ConvRow({
onSelect: () => void;
}) {
const profile = useProfile(partnerPubkey);
const name = profile?.displayName || profile?.name || shortenPubkey(partnerPubkey);
const name = profileName(profile, shortenPubkey(partnerPubkey));
const time = lastEvent.created_at ? timeAgo(lastEvent.created_at) : "";
return (
@@ -126,7 +126,7 @@ function ThreadPanel({
}) {
const { openProfile } = useUIStore();
const profile = useProfile(partnerPubkey);
const name = profile?.displayName || profile?.name || shortenPubkey(partnerPubkey);
const name = profileName(profile, shortenPubkey(partnerPubkey));
const [messages, setMessages] = useState<NDKEvent[]>([]);
const [loading, setLoading] = useState(true);