Skip to content

Reader: Improve user hovercard performance by using custom implementation#109865

Open
mehmoodak wants to merge 45 commits intoREAD-468/use-tanstack-query-on-user-profile-pagefrom
READ-460/improve-performance-of-gravatar-hovercard
Open

Reader: Improve user hovercard performance by using custom implementation#109865
mehmoodak wants to merge 45 commits intoREAD-468/use-tanstack-query-on-user-profile-pagefrom
READ-460/improve-performance-of-gravatar-hovercard

Conversation

@mehmoodak
Copy link
Copy Markdown
Member

@mehmoodak mehmoodak commented Apr 7, 2026

Closes: READ-460
Before reviewing this review: #109718, #109846, #109854 (and then a rebase with trunk will be needed)

Proposed Changes

  • Added custom implementation of user hovercards and removed gravatar hovercards.
  • Migrated all related files to TypeScript.
  • Prefetch WPCOM users for instant display while for non-WPCOM trigger fetch on hover.
  • Avoid layout shifts and show better user info than before.
  • Matches the layout with Figma designs.
Before After
image image
image image
image image
image image Simple Loader...

Here is the comparison video that shows improvements in WPCOM user hovercards (notice speed, better data and less layout shifts)

Screen.Recording.2026-04-08.at.6.32.57.AM.mov

Why are these changes being made?

On user avatars we were displaying Gravatar Hovercards. It does work but offers no control, makes extra API calls, had layout shifts and often times show incomplete data. Sometimes displaying hovercard takes 3s-7s which affects UX.

To avoid all of above we have move towards a custom implementation which offers:

  • More control. All components exists in our own codebase which offers more control like prefetching WPCOM users.
  • Less API calls. We have updated v1.1/users1 endpoint to send most of the data in 1 API call.
  • No layout shifts. Due to more control we now can decide early what to display which avoids layout shifts.
  • Better Data. Instead of just showing Gravatar hovercard we also fetch data against user login to get more info from WPCOM.

After all of above changes WPCOM user hovercards will display instantly (<0.1s) while non-WPCOM user hovercard will appear slightly fast (~2s - 3s).

Testing Instructions

We are using UserAvatar in following places. Test that each avatar is working as expected.

  • Comments Form in streams where we show logged in user avatar (no hovercard in this case).
  • Comments in streams where we show post comments (test hovercard as well). Try to test all streams.
  • Header of full post view.
  • In x-posts reader items (use any P2 that have cross posts)
  • Header in User Profile page (no hovercard in this case)

Pre-merge Checklist

  • Has the general commit checklist been followed? (PCYsg-hS-p2)
  • Have you written new tests for your changes?
  • Have you tested the feature in Simple (P9HQHe-k8-p2), Atomic (P9HQHe-jW-p2), and self-hosted Jetpack sites (PCYsg-g6b-p2)?
  • Have you checked for TypeScript, React or other console errors?
  • Have you tested accessibility for your changes? Ensure the feature remains usable with various user agents (e.g., browsers), interfaces (e.g., keyboard navigation), and assistive technologies (e.g., screen readers) (PCYsg-S3g-p2).
  • Have you used memoizing on expensive computations? More info in Memoizing with create-selector and Using memoizing selectors and Our Approach to Data
  • Have we added the "[Status] String Freeze" label as soon as any new strings were ready for translation (p4TIVU-5Jq-p2)?
    • For UI changes, have we tested the change in various languages (for example, ES, PT, FR, or DE)? The length of text and words vary significantly between languages.
  • For changes affecting Jetpack: Have we added the "[Status] Needs Privacy Updates" label if this pull request changes what data or activity we track or use (p4TIVU-aUh-p2)?

mehmoodak added 30 commits April 7, 2026 05:11
@mehmoodak mehmoodak self-assigned this Apr 7, 2026
@mehmoodak mehmoodak force-pushed the READ-468/use-tanstack-query-on-user-profile-page branch from 9f34e52 to 0ea831b Compare April 7, 2026 21:03
@mehmoodak mehmoodak changed the title Reader: Improve performance of gravatar hovercards Reader: Migrate away from Gravatar Hovercards for more control and improved performance Apr 7, 2026
@mehmoodak mehmoodak force-pushed the READ-460/improve-performance-of-gravatar-hovercard branch from be09f85 to b1924c3 Compare April 7, 2026 23:04
@matticbot
Copy link
Copy Markdown
Contributor

matticbot commented Apr 7, 2026

This PR modifies the release build for the following Calypso Apps:

For info about this notification, see here: PCYsg-OT6-p2

  • help-center
  • notifications
  • odyssey-stats
  • wpcom-block-editor

To test WordPress.com changes, run install-plugin.sh $pluginSlug READ-460/improve-performance-of-gravatar-hovercard on your sandbox.

Copy link
Copy Markdown
Member Author

@mehmoodak mehmoodak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added comments for easier review.

<header className="user-profile-header">
<div className="user-profile-header__user-info">
<UserAvatar user={ user } iconSize={ 56 } />
<UserAvatar user={ user } size={ 56 } hideHovercard />
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not display hovercard on header of user profile page.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keeping default Gravatar icon locally so that we can prevent HTTP calls.

Image

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PreloadedImage is a wrapper around the HTML img element which only displays the image once it has been fully loaded. This is useful to prevent layout shifts and display a placeholder while the image is loading.

Currently only using it on the avatar of hovercard but have plan to use it more in Reader codebase.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have made following changes in file. The functionality of the file is mostly same as before.

  • Converted the file to TypeScript.
  • Updated the code to use the data coming from parent instead of request our own. (this comes from v1.1/users endpoint)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Styles are moved from a single file to their dedicated component files. Most of the styles are same as before.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Styles are moved from a single file to their dedicated component files. Most of the styles are same as before.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Styles are moved from a single file to their dedicated component files. Most of the styles are same as before.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TanStack query to fetch info from Gravatar API. We'll only use this if we don't have a WPCOM user ID or login.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have made following changes in file. The functionality of the file is mostly same as before.

  • Converted the file to TypeScript.
  • Updated the code to use the data coming from parent instead of request our own. (this comes from v1.1/users endpoint)

@mehmoodak mehmoodak changed the title Reader: Migrate away from Gravatar Hovercards for more control and improved performance Reader: Use custom implementation of user hovercard Apr 8, 2026
@mehmoodak mehmoodak changed the title Reader: Use custom implementation of user hovercard Reader: Improve user hovercard performance by using custom implementation Apr 8, 2026
@mehmoodak mehmoodak marked this pull request as ready for review April 8, 2026 13:05
@mehmoodak mehmoodak requested a review from a team as a code owner April 8, 2026 13:05
@matticbot matticbot added the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label Apr 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants