fix(avatar): keep the GIF freeze-frame cache filling during virtualized scroll#770
Merged
Conversation
…ed scroll Animated GIF avatars still replayed on every scroll-in despite the #711 cache. First-frame extraction ran inside the Avatar effect and was cancelled on unmount, but a virtualized row routinely unmounts mid-decode while scrolling past, so cacheStaticFrame() was never reached and the shared cache never filled during scrolling, the exact case it was built for. Extraction now lives in a module-level extractFirstFrame() that runs to completion regardless of unmount and populates the cache; the hook only guards the setFrame state update. It also dedupes concurrent decodes of the same avatar and resolves cleanly if a blob URL is revoked mid-decode (img.onerror) instead of hanging.
mremond
added a commit
that referenced
this pull request
Jun 30, 2026
## Summary Follow-up to #770. Animated avatars are meant to show a frozen first frame and play only on hover. #770 fixed the freeze-frame cache for virtualized scrolling, but the freeze still only ever applied to literal GIFs. The decision "is this animated?" was made from the declared MIME type (`blob.type === 'image/gif'`). That misses the common real-world cases: - Many animated avatars are APNG or animated WebP, not GIF. WebKit animates all three in an `<img>`. - The SDK occupant-avatar path stores avatars as `image/png` regardless of the real format (`Profile.ts` hardcodes it for PEP avatars and defaults to it for vCard avatars with no `<TYPE>`), so even a GIF can arrive mistyped. So these avatars were never frozen and animated continuously (observed: kuyuhi in #XSF, an animated PNG). This detects animation from the actual image bytes instead of the declared type: GIF header, APNG `acTL` control chunk, or animated-WebP `ANIM` chunk. The existing canvas first-frame extraction already handles any decodable raster format, so the freeze now covers all three. Static JPEG/PNG/WebP are left untouched (no signature match), so there is no extra work for the common case. ### Known gap Animated AVIF/HEIF are not detected (rare as avatars, and WebKit animation support for them is limited). They would keep animating.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Animated GIF avatars are meant to show a frozen first frame and only play on hover. After message-list virtualization went default-on, they replayed their opening frames on every scroll-in. #711 added a shared first-frame cache to fix this, but the cache never actually filled during scrolling.
The first-frame extraction (fetch, decode, canvas) ran inside the Avatar component's effect and was cancelled on unmount. A virtualized row routinely unmounts mid-decode as it scrolls past, so
cacheStaticFrame()was never reached and the shared cache stayed empty during scrolling, the one scenario it was built for. The cache only filled for avatars that happened to sit still long enough.This moves extraction into a module-level
extractFirstFrame()that runs to completion regardless of whether the requesting row unmounted, populating the shared cache from there. The hook now only guards the React state update, so it never sets state on an unmounted row. The function also dedupes concurrent decodes of the same avatar (it can be mounted in several visible rows at once) and resolves cleanly viaimg.onerrorif a blob URL is revoked mid-decode instead of hanging.A regression test covers the race the previous tests missed: a row that unmounts mid-extraction and then remounts must show the frozen frame with no re-fetch.
Known limitation
The very first decode of a given GIF in a session still animates briefly (tens of ms) until its first frame is extracted, which is inherent to client-side extraction. After that one-time decode, every subsequent mount and scroll-in is frozen. Eliminating that first flash would require eagerly warming the cache when avatars are received, tracked separately.