Skip to content

Wrong avatars shown for other users after list scroll (MxcImage race) #125

@ginbun

Description

@ginbun

Description

After scrolling through a chat or room list, other users' avatars sometimes display the current logged-in user's profile picture instead of their own.

Steps to reproduce

  1. Log in with a custom profile avatar.
  2. Open a group chat or room list with multiple users who have different avatars.
  3. Scroll quickly through messages or the chat list.
  4. Notice that some other users' avatars show your own photo.

Expected behavior

Each avatar should always match the correct user's MXC URI, regardless of scroll position or list recycling.

Actual behavior

Stale image data from a previously bound avatar URI is applied to a different user after the widget is rebound during list recycling.

Root cause

MxcImage._load() is async and does not verify that the widget is still bound to the same URI when the download completes. When a list item is recycled:

  1. Widget loads the current user's avatar URI
  2. List scroll rebinds the widget to another user
  3. The earlier download completes and writes image bytes under the new user's cache key
  4. The wrong avatar is displayed and may persist in the in-memory LRU cache

Users without avatars still mount MxcImage with uri: null, which can retain stale image data from a previous binding.

Proposed fix

  • Capture uri, event, and cache key at the start of _load() and discard the response if any of them changed before setState
  • For users without an avatar, render the letter fallback directly and skip MxcImage
  • Add a stable RepaintBoundary key based on URI, display name, and size

Affected files

  • lib/widgets/mxc_image.dart
  • lib/widgets/avatar.dart

Environment

  • Reproducible on Linux desktop; likely affects all platforms with scrollable avatar lists

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions