diff --git a/app/frontend/src/app/[username]/page.tsx b/app/frontend/src/app/[username]/page.tsx index 44400c935..4cf8acc8d 100644 --- a/app/frontend/src/app/[username]/page.tsx +++ b/app/frontend/src/app/[username]/page.tsx @@ -11,6 +11,12 @@ import type { Profile } from "@/types/profile"; const FOCUS_RING_CLASS = "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-indigo-300 focus-visible:ring-offset-2 focus-visible:ring-offset-black"; +const ERROR_COPY = { + invalidUsername: "Invalid username", + notFound: "Username not found or profile is private", + fallback: "Failed to load profile", +} as const; + export default function PublicProfile() { const params = useParams(); const router = useRouter(); @@ -19,6 +25,7 @@ export default function PublicProfile() { const [profile, setProfile] = useState(null); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); + const [avatarFailed, setAvatarFailed] = useState(false); const [paymentForm, setPaymentForm] = useState({ amount: "", @@ -29,18 +36,22 @@ export default function PublicProfile() { useEffect(() => { let mounted = true; + // Reset per-username state so navigating between profiles never shows + // stale content (avoids flicker / metadata inconsistency across refreshes). + setProfile(null); + setAvatarFailed(false); + setError(null); + setLoading(true); + async function fetchProfile() { if (!username) { - setError("Invalid username"); + setError(ERROR_COPY.invalidUsername); setLoading(false); return; } try { - setLoading(true); - setError(null); const data = await getProfile(username); - if (mounted) { setProfile(data); } @@ -48,11 +59,11 @@ export default function PublicProfile() { if (!mounted) return; if (err instanceof ProfileNotFoundError) { - setError("Username not found or profile is private"); + setError(ERROR_COPY.notFound); } else if (err instanceof Error) { setError(err.message); } else { - setError("Failed to load profile"); + setError(ERROR_COPY.fallback); } setProfile(null); } finally { @@ -71,7 +82,11 @@ export default function PublicProfile() { if (loading) { return ( -
+

Loading profile...

@@ -82,11 +97,14 @@ export default function PublicProfile() { if (error || !profile) { return ( -
+

404

- {error || "Username not found"} + {error || ERROR_COPY.notFound}