Skip to content

Conversation

wankun-tcj
Copy link

Fix Avatar Display Issue in Pull Request Tree View

Fixes #6914

Problem Description

Logged-in users were seeing random generated avatars (Gravatar "retro" style) instead of their actual GitHub profile avatars in the VS Code GitHub Pull Request extension's tree view sidebar. Other users' avatars displayed correctly, but the current user's avatar was consistently showing as a random generated image.

Root Cause

The issue was caused by two interconnected problems:

  1. Incorrect Avatar Fallback Logic: The getAvatarWithEnterpriseFallback function was forcing Gravatar fallback for enterprise environments, even when valid GitHub avatar URLs were available.

  2. Persistent Avatar Caching: The avatar caching mechanism used cache keys based only on user login (e.g., user123.jpg), not the avatar URL. Once a Gravatar image was cached, it would continue to be served even after fixing the URL logic.

Solution

1. Fixed Avatar URL Logic (src/github/utils.ts)

  • Non-enterprise environments: Always return the original GitHub avatar URL
  • Enterprise environments: Prioritize GitHub avatars over Gravatar fallback
  • Fallback logic: Only use Gravatar when no GitHub avatar URL is available

2. Implemented Cache Invalidation (src/common/uri.ts)

  • Cache keys now include a hash of the avatar URL
  • Format changed from {userId}.jpg to {userId}_{urlHash}.jpg
  • Automatic cache invalidation when avatar URLs change
  • Maintains backward compatibility for users without avatar URLs

Technical Details

Before:

// Always forced Gravatar for enterprise
if (isEnterpriseRemote) {
    return generateGravatarUrl(hash);
}

After:

// Prioritize GitHub avatars, fallback only when needed
if (!isEnterpriseRemote) {
    return avatarUrl;
}
if (avatarUrl && avatarUrl.trim()) {
    return avatarUrl;
}
// Only fallback to Gravatar if no GitHub avatar available

Cache Key Generation:

function iconFilename(user: IAccount | ITeam): string {
    const baseId = reviewerId(user);
    if (user.avatarUrl) {
        const urlHash = user.avatarUrl.split('').reduce((a, b) => {
            a = ((a << 5) - a) + b.charCodeAt(0);
            return a & a;
        }, 0);
        return `${baseId}_${Math.abs(urlHash)}.jpg`;
    }
    return `${baseId}.jpg`;
}

Files Changed

  • src/github/utils.ts - Core avatar URL logic fix
  • src/common/uri.ts - Cache invalidation mechanism
  • package.json - Version bump

Testing

  • ✅ Verified correct GitHub avatar display for logged-in users
  • ✅ Confirmed cache invalidation works with URL changes
  • ✅ Tested compatibility with both enterprise and non-enterprise environments
  • ✅ Validated that other users' avatars remain unaffected

Impact

  • Fixes avatar display issue for all logged-in users
  • Improves user experience by showing correct profile pictures
  • Maintains backward compatibility
  • No breaking changes to existing functionality

- Fix getAvatarWithEnterpriseFallback to prioritize GitHub avatars over Gravatar fallback
- Implement cache invalidation by including avatar URL hash in cache keys
- Ensure logged-in users see their actual GitHub profile avatars instead of random generated ones

Fixes microsoft#6914
@wankun-tcj
Copy link
Author

@microsoft-github-policy-service agree company="Wano"

Copy link
Contributor

@wankun-tcj the command you issued was incorrect. Please try again.

Examples are:

@microsoft-github-policy-service agree

and

@microsoft-github-policy-service agree company="your company"

@wankun-tcj
Copy link
Author

@microsoft-github-policy-service agree company="Wano"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

How to update avatars in the Pull Requests view?
1 participant