mirror of
https://github.com/hoornet/vega.git
synced 2026-05-08 05:09:12 -07:00
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:
@@ -1,7 +1,7 @@
|
||||
import { NDKEvent, nip19 } from "@nostr-dev-kit/ndk";
|
||||
import { useProfile } from "../../hooks/useProfile";
|
||||
import { useUIStore } from "../../stores/ui";
|
||||
import { shortenPubkey } from "../../lib/utils";
|
||||
import { shortenPubkey, profileName } from "../../lib/utils";
|
||||
|
||||
function getTag(event: NDKEvent, name: string): string {
|
||||
return event.tags.find((t) => t[0] === name)?.[1] ?? "";
|
||||
@@ -32,7 +32,7 @@ export function ArticleCard({ event }: { event: NDKEvent }) {
|
||||
const publishedAt = parseInt(getTag(event, "published_at")) || event.created_at || null;
|
||||
const naddr = buildNaddr(event);
|
||||
|
||||
const authorName = profile?.displayName || profile?.name || shortenPubkey(event.pubkey);
|
||||
const authorName = profileName(profile, shortenPubkey(event.pubkey));
|
||||
const date = publishedAt
|
||||
? new Date(publishedAt * 1000).toLocaleDateString(undefined, { year: "numeric", month: "short", day: "numeric" })
|
||||
: null;
|
||||
|
||||
@@ -8,6 +8,7 @@ import { useBookmarkStore } from "../../stores/bookmark";
|
||||
import { fetchArticle, publishReaction, publishRepost, publishNote } from "../../lib/nostr";
|
||||
import { nip19 } from "@nostr-dev-kit/ndk";
|
||||
import { useProfile } from "../../hooks/useProfile";
|
||||
import { profileName } from "../../lib/utils";
|
||||
import { ZapModal } from "../zap/ZapModal";
|
||||
|
||||
// ── Types ────────────────────────────────────────────────────────────────────
|
||||
@@ -33,7 +34,7 @@ function getTags(event: NDKEvent, name: string): string[] {
|
||||
function AuthorRow({ pubkey, publishedAt, readingTime }: { pubkey: string; publishedAt: number | null; readingTime?: number }) {
|
||||
const { openProfile } = useUIStore();
|
||||
const profile = useProfile(pubkey);
|
||||
const name = profile?.displayName || profile?.name || pubkey.slice(0, 12) + "…";
|
||||
const name = profileName(profile, pubkey.slice(0, 12) + "…");
|
||||
const date = publishedAt
|
||||
? new Date(publishedAt * 1000).toLocaleDateString(undefined, { year: "numeric", month: "long", day: "numeric" })
|
||||
: null;
|
||||
@@ -122,7 +123,7 @@ export function ArticleView() {
|
||||
const articleTags = event ? getTags(event, "t") : [];
|
||||
const authorPubkey = event?.pubkey ?? "";
|
||||
const authorProfile = useProfile(authorPubkey);
|
||||
const authorName = authorProfile?.displayName || authorProfile?.name || authorPubkey.slice(0, 12) + "…";
|
||||
const authorName = profileName(authorProfile, authorPubkey.slice(0, 12) + "…");
|
||||
|
||||
const bodyHtml = event?.content ? renderMarkdown(event.content) : "";
|
||||
const wordCount = event?.content?.trim().split(/\s+/).length ?? 0;
|
||||
|
||||
Reference in New Issue
Block a user