Skip to content

refactor(studio): render message avatars with the Avatar primitive - #2351

Merged
peppescg merged 2 commits into
mainfrom
refactor/studio-message-avatar-2338
Oct 15, 2026
Merged

peppescg merged 2 commits into
mainfrom
refactor/studio-message-avatar-2338

Conversation

@peppescg

Copy link
Copy Markdown
Contributor

Summary

Message avatars now use the Avatar primitive (components/ui/avatar.tsx) instead of a hand-rolled <img> or <span>. This is the Avatar's first call site in Studio. Size, colours, icons, and accessible names stay the same. Six of the eight captures are pixel-identical; the other two differ only in the anti-aliasing of the circle's edge (details under No regression).

Closes #2338
Part of #2201
Part of #2210

What changed

  • features/chat/message-bubble.tsx: MessageAvatar keeps its props (avatarUrl, fallback, name), so its two callers (chat-transcript.tsx and chat-workspace.tsx, both in other open PRs) don't change.
    • Avatar keeps the size-7 lg:size-9 frame. size-8 is the primitive's default, and tailwind-merge drops it.
    • When a picture is configured, AvatarImage renders it with alt={name} and object-cover. The Root's overflow-hidden rounded-full crops it to the circle.
    • AvatarFallback draws the brand circle with the bot icon for the agent, or the muted circle with the person icon for the user. These are the same classes and icons as before.
    • With no picture configured, the Root is aria-hidden, as the old <span> was. The author line beside it already names the speaker.
  • features/chat/transcript-alignment.test.tsx: one existing test changed. The reason is under No regression.

The prototype (stack-08, features/chat/message-bubble.tsx) also hand-rolls this avatar, as a local Avatar function. The frame, colours, and icons here match it.

Behaviour differences

These come from the primitive's standard behaviour. Neither affects the captured surfaces:

  • A picture that fails to load now shows the role's fallback circle and icon. Before, the browser drew its broken-image glyph.
  • While a picture loads, the fallback circle shows until the image arrives. A data URL (how Studio stores profile pictures) loads within a frame, so the screenshots don't show it.

In both states the fallback has role="img" and aria-label={name}, so the avatar keeps the speaker's name as its accessible name, as the old <img alt> did.

No regression

  • Pins first (59454e715, passing on the unchanged code and unchanged after the swap). message-bubble.pinning.test.tsx has 5 tests:

    • the agent and user fallback icons and colours;
    • the frame size at both breakpoints;
    • aria-hidden and no img role when no picture is configured;
    • a loaded picture is an <img> named after the speaker, with its src, cropped round;
    • the speaker's name before a picture loads and after it fails.

    The class checks read the whole avatar subtree, so they hold whether the frame and the colours sit on one element or on a Root and its Fallback.

  • Modified test, justified: transcript-alignment.test.tsx › "shows the configured avatars beside each speaker" read src synchronously. happy-dom never loads images, and AvatarImage renders only after the image loads. The test now stubs an already-loaded Image with vi.stubGlobal and waits for both images. Every assertion is unchanged, and the test passes on the old code too.

  • Mutation proof. Each mutation was applied alone and the focused tests rerun. Every one fails at least one test:

    Mutation Failing tests
    Agent fallback gets the user's muted colours 1
    No speaker name on the fallback when a picture is configured 2 (loading, failed)
    Root loses aria-hidden when no picture is configured 2
    Frame falls back to the primitive's size-8 3
    AvatarImage removed 2 (pin and transcript test)
    alt="" on the image 2
    Bot icon for both roles 1
  • Pixels: 8 captures (2 states × desktop and 390px × light and dark), with a second Before capture as the noise floor. pixel-report.txt in the asset folder has the counts.

    • 6 are identical to Before: both picture captures at every size, and the fallback avatars at 390px.
    • The fallback avatars at desktop size differ in 147 pixels (light) and 143 (dark). All of them are in the agent avatar's 36px circle, mostly on its rim (largest channel difference 63/255); the few inside it differ by at most 6/255. The frame, the colours and the icon's position are unchanged; the difference is anti-aliasing from the Root's overflow-hidden rounded-full clipping a Fallback that is itself rounded-full. The composites box it in red.
  • Base check: the pins and the modified transcript test pass on the code from 59454e715 (24/24) and on the head.

Screenshots

Before is origin/main (1210721be), After is this branch (6412e7fcf), and Prototype is stack-08. Red boxes mark pixels that differ between Before and After. After matches the prototype's frame, colours and icons; the prototype's transcript has no configured pictures, so its column shows the fallback in both states.

Fallback avatars, desktop, light (the boxed avatar is the edge anti-aliasing difference described above)

avatars-fallback-desktop-light

Configured pictures, desktop, light (identical)

avatars-picture-desktop-light

Desktop dark and 390px, light and dark

Fallback avatars, desktop, dark (edge anti-aliasing only):

avatars-fallback-desktop-dark

Configured pictures, desktop, dark (identical):

avatars-picture-desktop-dark

Fallback avatars, 390px, light and dark (identical):

avatars-fallback-mobile-light
avatars-fallback-mobile-dark

Configured pictures, 390px, light and dark (identical):

avatars-picture-mobile-light
avatars-picture-mobile-dark

Gates

On the head rebased onto origin/main (1210721be):

  • task studio:check: passed. Web 1493 tests in 172 files, server 210 tests in 26 files.
  • task studio:browser: passed. 124 passed, 30 skipped.

🤖 Generated with Claude Code

peppescg and others added 2 commits October 15, 2026 10:37
Pins the accessible name, fallback icons and colours, and frame size of
MessageAvatar, including the loading and failed-picture states.

Refs #2338

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
MessageAvatar now builds on Avatar, AvatarImage and AvatarFallback with the
same frame, colours, icons and accessible names. The fallback carries the
speaker's name while a configured picture loads or after it fails, so the
avatar keeps one accessible name in every state.

The transcript avatar test stubs an already-loaded Image: happy-dom never
loads pictures, and AvatarImage renders only once one has loaded.

Closes #2338

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

@kantord kantord left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for this, the Avatar swap is clean and the accessible name holds in all three states (loading, loaded, failed), and the pixel differences are honestly disclosed. Approving, with a few non-blocking nits:

  • The PR text names chat-workspace.tsx as a caller of MessageAvatar. That may be stale now that #2322 moved Message out of it, so it is worth re-checking the description.
  • The tests stub window.Image (complete, naturalWidth, EventTarget), which couples them to how Radix Avatar detects image load. Acceptable, but a Radix change could break every picture test.
  • message-bubble.pinning.test.tsx leans on class names. The role and name assertions are the valuable ones.
  • Worth a quick look in a browser: AvatarImage renders nothing until the image has loaded, so a first network load shows the fallback circle for a moment. It is probably invisible for cached images, but I did not run it.

Fully or partially written by an AI agent.

@peppescg
peppescg merged commit acb4c4d into main Oct 15, 2026
31 checks passed
@peppescg
peppescg deleted the refactor/studio-message-avatar-2338 branch October 15, 2026 17:01
@toolhive-release-app toolhive-release-app Bot mentioned this pull request Oct 20, 2026
2 tasks
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.

Studio: render message avatars with the Avatar primitive

2 participants