From 282de15601283833d875d55856497da945543eac Mon Sep 17 00:00:00 2001 From: Evie Gauthier Date: Sat, 28 Mar 2026 01:12:49 -0400 Subject: [PATCH] fix: recover profile and avatar loading --- src/app/components/room-avatar/RoomAvatar.tsx | 6 +++++- src/app/components/user-avatar/UserAvatar.tsx | 6 +++++- src/app/hooks/useUserProfile.ts | 12 +++++++----- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/app/components/room-avatar/RoomAvatar.tsx b/src/app/components/room-avatar/RoomAvatar.tsx index 356d9dbc..33f9f688 100644 --- a/src/app/components/room-avatar/RoomAvatar.tsx +++ b/src/app/components/room-avatar/RoomAvatar.tsx @@ -1,6 +1,6 @@ import { JoinRule } from '$types/matrix-sdk'; import { AvatarFallback, Icon, Icons, color } from 'folds'; -import { ComponentProps, ReactNode, forwardRef, useState } from 'react'; +import { ComponentProps, ReactNode, forwardRef, useEffect, useState } from 'react'; import { getRoomIconSrc } from '$utils/room'; import colorMXID from '$utils/colorMXID'; import * as css from './RoomAvatar.css'; @@ -17,6 +17,10 @@ type RoomAvatarProps = { export function RoomAvatar({ roomId, src, alt, renderFallback, uniformIcons }: RoomAvatarProps) { const [error, setError] = useState(false); + useEffect(() => { + setError(false); + }, [src]); + if (!src || error) { return ( { + setError(false); + }, [src]); + const handleLoad: ReactEventHandler = (evt) => { evt.currentTarget.setAttribute('data-image-loaded', 'true'); }; diff --git a/src/app/hooks/useUserProfile.ts b/src/app/hooks/useUserProfile.ts index d1de6e89..b50a4296 100644 --- a/src/app/hooks/useUserProfile.ts +++ b/src/app/hooks/useUserProfile.ts @@ -32,6 +32,7 @@ export type UserProfile = { }; const normalizeInfo = (info: any): UserProfile => { + const msc4440Bio = info['gay.fomx.biography'] as MSC4440Bio | undefined; const knownKeys = new Set([ 'avatar_url', 'displayname', @@ -60,10 +61,7 @@ const normalizeInfo = (info: any): UserProfile => { displayName: info.displayname, pronouns: info['io.fsky.nyx.pronouns'], timezone: info['us.cloke.msc4175.tz'] || info['m.tz'], - bio: - (info['gay.fomx.biography'] satisfies MSC4440Bio)['m.text'][0].body || - info['moe.sable.app.bio'] || - info['chat.commet.profile_bio'], + bio: msc4440Bio?.['m.text']?.[0]?.body || info['moe.sable.app.bio'] || info['chat.commet.profile_bio'], status: info['chat.commet.profile_status'], bannerUrl: info['chat.commet.profile_banner'], nameColor: info['moe.sable.app.name_color'], @@ -103,7 +101,11 @@ export const useUserProfile = ( const cached = useAtomValue(userSelector); const setGlobalProfiles = useSetAtom(profilesCacheAtom); - const needsFetch = !!userId && userId !== 'undefined' && !cached?._fetched; + const hasOnlyFetchedMarker = + cached?._fetched === true && Object.keys(cached).every((key) => key === '_fetched'); + + const needsFetch = + !!userId && userId !== 'undefined' && (!cached?._fetched || hasOnlyFetchedMarker); useEffect(() => { if (!needsFetch) return undefined;