AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
fix(frontend): use consistent marble avatar fallback across navbar and marketplace (#13775)
Krzysztof Czerwinski64f832386e60
diff --git a/autogpt_platform/frontend/src/app/(platform)/marketplace/components/AgentInfo/AgentInfo.tsx b/autogpt_platform/frontend/src/app/(platform)/marketplace/components/AgentInfo/AgentInfo.tsxindex d12402d52e..59ceeeb24b 100644--- a/autogpt_platform/frontend/src/app/(platform)/marketplace/components/AgentInfo/AgentInfo.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/marketplace/components/AgentInfo/AgentInfo.tsx@@ -164,7 +164,7 @@ export const AgentInfo = ({{creatorAvatar && (<AvatarImage src={creatorAvatar} alt={`${creator} avatar`} />)}- <AvatarFallback size={28}>{creator.charAt(0)}</AvatarFallback>+ <AvatarFallback size={28}>{creator}</AvatarFallback></Avatar><Text variant="body" className="text-md">bydiff --git a/autogpt_platform/frontend/src/app/(platform)/marketplace/components/CreatorCard/CreatorCard.tsx b/autogpt_platform/frontend/src/app/(platform)/marketplace/components/CreatorCard/CreatorCard.tsxindex c46656188c..75de91e451 100644--- a/autogpt_platform/frontend/src/app/(platform)/marketplace/components/CreatorCard/CreatorCard.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/marketplace/components/CreatorCard/CreatorCard.tsx@@ -9,6 +9,7 @@ import { backgroundColor } from "./helper";interface Props {creatorName: string;+ creatorUsername?: string;creatorImage: string | null;bio: string;agentsUploaded: number;@@ -18,6 +19,7 @@ interface Props {export function CreatorCard({creatorName,+ creatorUsername,creatorImage,bio,agentsUploaded,@@ -36,7 +38,9 @@ export function CreatorCard({{creatorImage && (<AvatarImage src={creatorImage} alt={`${creatorName} avatar`} />)}- <AvatarFallback size={56}>{creatorName.charAt(0)}</AvatarFallback>+ <AvatarFallback size={56}>+ {creatorUsername || creatorName}+ </AvatarFallback></Avatar><div className="mt-3 flex w-full flex-1 flex-col">diff --git a/autogpt_platform/frontend/src/app/(platform)/marketplace/components/CreatorInfoCard/CreatorInfoCard.tsx b/autogpt_platform/frontend/src/app/(platform)/marketplace/components/CreatorInfoCard/CreatorInfoCard.tsxindex addefc7ca7..0d15e66487 100644--- a/autogpt_platform/frontend/src/app/(platform)/marketplace/components/CreatorInfoCard/CreatorInfoCard.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/marketplace/components/CreatorInfoCard/CreatorInfoCard.tsx@@ -41,7 +41,7 @@ export const CreatorInfoCard = ({size={130}className="h-[100px] w-[100px] sm:h-[130px] sm:w-[130px]">- {username.charAt(0)}+ {username}</AvatarFallback></Avatar><div className="flex w-full flex-col items-start justify-start gap-1.5">diff --git a/autogpt_platform/frontend/src/app/(platform)/marketplace/components/FeaturedAgentCard/FeaturedAgentCard.tsx b/autogpt_platform/frontend/src/app/(platform)/marketplace/components/FeaturedAgentCard/FeaturedAgentCard.tsxindex 0d341068e8..a4c4c540a0 100644--- a/autogpt_platform/frontend/src/app/(platform)/marketplace/components/FeaturedAgentCard/FeaturedAgentCard.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/marketplace/components/FeaturedAgentCard/FeaturedAgentCard.tsx@@ -109,9 +109,7 @@ export function FeaturedAgentCard({ agent, backgroundColor }: Props) {alt={`${agent.creator} creator avatar`}/>)}- <AvatarFallback size={20}>- {agent.creator.charAt(0)}- </AvatarFallback>+ <AvatarFallback size={20}>{agent.creator}</AvatarFallback></Avatar><span className="truncate text-[13px] text-zinc-500">by {agent.creator}diff --git a/autogpt_platform/frontend/src/app/(platform)/marketplace/components/FeaturedCreators/FeaturedCreators.tsx b/autogpt_platform/frontend/src/app/(platform)/marketplace/components/FeaturedCreators/FeaturedCreators.tsxindex 58f534515a..68f10f3cea 100644--- a/autogpt_platform/frontend/src/app/(platform)/marketplace/components/FeaturedCreators/FeaturedCreators.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/marketplace/components/FeaturedCreators/FeaturedCreators.tsx@@ -34,6 +34,7 @@ export const FeaturedCreators = ({<CreatorCardkey={index}creatorName={creator.name || creator.username}+ creatorUsername={creator.username}creatorImage={creator.avatar_url}bio={creator.description}agentsUploaded={creator.num_agents}diff --git a/autogpt_platform/frontend/src/app/(platform)/marketplace/components/StoreCard/StoreCard.tsx b/autogpt_platform/frontend/src/app/(platform)/marketplace/components/StoreCard/StoreCard.tsxindex a57d7fdd41..c9db20e5dc 100644--- a/autogpt_platform/frontend/src/app/(platform)/marketplace/components/StoreCard/StoreCard.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/marketplace/components/StoreCard/StoreCard.tsx@@ -96,7 +96,7 @@ export function StoreCard({alt={`${creatorName} creator avatar`}/>)}- <AvatarFallback size={20}>{creatorName.charAt(0)}</AvatarFallback>+ <AvatarFallback size={20}>{creatorName}</AvatarFallback></Avatar><span className="truncate text-[13px] text-zinc-500">by {creatorName}diff --git a/autogpt_platform/frontend/src/app/(platform)/marketplace/creator/[creator]/components/MainCreatorPage/MainCreatorPage.tsx b/autogpt_platform/frontend/src/app/(platform)/marketplace/creator/[creator]/components/MainCreatorPage/MainCreatorPage.tsxindex a035f5f577..4bf96c10e1 100644--- a/autogpt_platform/frontend/src/app/(platform)/marketplace/creator/[creator]/components/MainCreatorPage/MainCreatorPage.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/marketplace/creator/[creator]/components/MainCreatorPage/MainCreatorPage.tsx@@ -86,7 +86,7 @@ export function MainCreatorPage({ params }: Props) {/>)}<AvatarFallback size={96}>- {creator.name.charAt(0)}+ {creator.username}</AvatarFallback></Avatar>diff --git a/autogpt_platform/frontend/src/components/atoms/Avatar/Avatar.tsx b/autogpt_platform/frontend/src/components/atoms/Avatar/Avatar.tsxindex 56131af7df..1a401332b7 100644--- a/autogpt_platform/frontend/src/components/atoms/Avatar/Avatar.tsx+++ b/autogpt_platform/frontend/src/components/atoms/Avatar/Avatar.tsx@@ -126,7 +126,7 @@ export function AvatarImage({// eslint-disable-next-line @next/next/no-img-element<imgsrc={normalizedSrc}- alt={alt || "Avatar image"}+ alt={alt ?? "Avatar image"}className={cn("h-full w-full object-cover", className)}width={computedWidth}height={computedHeight}@@ -147,8 +147,9 @@ export function AvatarImage({return (<Image+ {...rest}src={normalizedSrc}- alt={alt || "Avatar image"}+ alt={alt ?? "Avatar image"}className={cn("h-full w-full object-cover", className)}width={fill ? undefined : computedWidth}height={fill ? undefined : computedHeight}@@ -176,12 +177,18 @@ export function AvatarFallback({const show = !isLoaded || !hasImage;if (!show) return null;const computedSize = _size || getAvatarSizeFromClassName(className) || 40;+ // Trim the seed so call sites with padded names render the same gradientconst name =- typeof children === "string" && children.trim() ? children : "User";+ typeof children === "string" && children.trim() ? children.trim() : "User";return (<span+ // decorative gradient — hide from AT so the marble's unnamed role="img"+ // svg doesn't surface as an axe violation+ aria-hidden="true"className={cn(- "flex h-full w-full items-center justify-center rounded-full bg-transparent text-lg text-neutral-600",+ // absolute so the fallback overlays (not flows beside) the image while it loads;+ // svg stretched to fill so the marble always matches the avatar size+ "absolute inset-0 flex items-center justify-center rounded-full bg-transparent text-lg text-neutral-600 [&>svg]:h-full [&>svg]:w-full",className,)}{...props}diff --git a/autogpt_platform/frontend/src/components/layout/AppSidebar/components/SidebarUserActions/SidebarUserActions.tsx b/autogpt_platform/frontend/src/components/layout/AppSidebar/components/SidebarUserActions/SidebarUserActions.tsxindex 291a2bb51a..4651110d16 100644--- a/autogpt_platform/frontend/src/components/layout/AppSidebar/components/SidebarUserActions/SidebarUserActions.tsx+++ b/autogpt_platform/frontend/src/components/layout/AppSidebar/components/SidebarUserActions/SidebarUserActions.tsx@@ -43,6 +43,7 @@ export function SidebarUserActions() {const accountMenu = (<AccountMenuuserName={profile?.name || profile?.username}+ userHandle={profile?.username}userEmail={user?.email}avatarSrc={profile?.avatar_url ?? ""}menuItemGroups={dynamicMenuItems}diff --git a/autogpt_platform/frontend/src/components/layout/Navbar/Navbar.tsx b/autogpt_platform/frontend/src/components/layout/Navbar/Navbar.tsxindex e882865eae..fc1e8bd22f 100644--- a/autogpt_platform/frontend/src/components/layout/Navbar/Navbar.tsx+++ b/autogpt_platform/frontend/src/components/layout/Navbar/Navbar.tsx@@ -119,6 +119,7 @@ export function Navbar() {{profile && <Wallet key={profile.username} />}<AccountMenuuserName={profile?.name || profile?.username}+ userHandle={profile?.username}userEmail={user?.email}avatarSrc={profile?.avatar_url ?? ""}menuItemGroups={dynamicMenuItems}diff --git a/autogpt_platform/frontend/src/components/layout/Navbar/components/AccountMenu/AccountMenu.tsx b/autogpt_platform/frontend/src/components/layout/Navbar/components/AccountMenu/AccountMenu.tsxindex c595b1a4a6..24f540821f 100644--- a/autogpt_platform/frontend/src/components/layout/Navbar/components/AccountMenu/AccountMenu.tsx+++ b/autogpt_platform/frontend/src/components/layout/Navbar/components/AccountMenu/AccountMenu.tsx@@ -14,6 +14,7 @@ import { getAccountMenuIcon } from "./helpers";interface Props {userName?: string;+ userHandle?: string;userEmail?: string;avatarSrc?: string;hideNavBarUsername?: boolean;@@ -29,6 +30,7 @@ interface Props {export function AccountMenu({userName,+ userHandle,userEmail,avatarSrc,menuItemGroups,@@ -43,6 +45,7 @@ export function AccountMenu({return (<AccountMenuNewLayoutuserName={userName}+ userHandle={userHandle}userEmail={userEmail}avatarSrc={avatarSrc}menuItemGroups={menuItemGroups}@@ -64,7 +67,12 @@ export function AccountMenu({aria-haspopup="true"data-testid="profile-popout-menu-trigger">- <InitialAvatar src={avatarSrc} name={userName} className="h-8 w-8" />+ <InitialAvatar+ src={avatarSrc}+ name={userName}+ username={userHandle}+ className="h-8 w-8"+ /></button></PopoverTrigger>@@ -76,7 +84,11 @@ export function AccountMenu({data-testid="account-menu-popover"><div className="flex items-center gap-3 px-4 py-3">- <InitialAvatar src={avatarSrc} name={userName} />+ <InitialAvatar+ src={avatarSrc}+ name={userName}+ username={userHandle}+ /><div className="flex min-w-0 flex-1 flex-col gap-1">{isLoading || !userName || !userEmail ? (<>diff --git a/autogpt_platform/frontend/src/components/layout/Navbar/components/AccountMenu/AccountMenuNewLayout.tsx b/autogpt_platform/frontend/src/components/layout/Navbar/components/AccountMenu/AccountMenuNewLayout.tsxindex 1089e75800..2ef91339d9 100644--- a/autogpt_platform/frontend/src/components/layout/Navbar/components/AccountMenu/AccountMenuNewLayout.tsx+++ b/autogpt_platform/frontend/src/components/layout/Navbar/components/AccountMenu/AccountMenuNewLayout.tsx@@ -14,6 +14,7 @@ import { getAccountMenuIcon } from "./helpers";interface Props {userName?: string;+ userHandle?: string;userEmail?: string;avatarSrc?: string;menuItemGroups: MenuItemGroup[];@@ -24,6 +25,7 @@ interface Props {export function AccountMenuNewLayout({userName,+ userHandle,userEmail,avatarSrc,menuItemGroups,@@ -44,7 +46,12 @@ export function AccountMenuNewLayout({aria-haspopup="true"data-testid="profile-popout-menu-trigger">- <InitialAvatar src={avatarSrc} name={userName} className="h-8 w-8" />+ <InitialAvatar+ src={avatarSrc}+ name={userName}+ username={userHandle}+ className="h-8 w-8"+ /></button></PopoverTrigger>@@ -59,6 +66,7 @@ export function AccountMenuNewLayout({<div className="px-2"><AccountMenuHeaderuserName={userName}+ userHandle={userHandle}userEmail={userEmail}avatarSrc={avatarSrc}isLoading={isLoading}diff --git a/autogpt_platform/frontend/src/components/layout/Navbar/components/AccountMenu/__tests__/AccountMenu.test.tsx b/autogpt_platform/frontend/src/components/layout/Navbar/components/AccountMenu/__tests__/AccountMenu.test.tsxindex 0707c72dac..affa57f6a3 100644--- a/autogpt_platform/frontend/src/components/layout/Navbar/components/AccountMenu/__tests__/AccountMenu.test.tsx+++ b/autogpt_platform/frontend/src/components/layout/Navbar/components/AccountMenu/__tests__/AccountMenu.test.tsx@@ -2,8 +2,14 @@ import { IconType } from "@/components/__legacy__/ui/icons";import { render, screen } from "@/tests/integrations/test-utils";import { describe, expect, test, vi } from "vitest";import { AccountMenu } from "../AccountMenu";+import { InitialAvatar } from "../components/InitialAvatar";import { MenuItemGroup } from "../../../helpers";+function getFallbackSVG(root: HTMLElement) {+ const svg = root.querySelector("svg");+ return svg?.innerHTML.replace(/:r[0-9a-z]+:/g, "id") ?? null;+}+vi.mock("next/link", () => ({__esModule: true,default: ({ children, href, ...props }: any) => (@@ -134,17 +140,21 @@ describe("AccountMenu", () => {expect(helpLink?.getAttribute("rel")).toBe("noopener noreferrer");});- test("renders profile trigger with avatar fallback", () => {+ test("renders profile trigger with avatar fallback seeded by the user", () => {render(<AccountMenuuserName="Ada"+ userHandle="ada"userEmail="[email protected]"menuItemGroups={baseGroups}/>,);+ const reference = render(<InitialAvatar name="ada" />);- expect(screen.getByTestId("profile-popout-menu-trigger")).toBeDefined();- expect(screen.getAllByText("A").length).toBeGreaterThan(0);+ const trigger = screen.getByTestId("profile-popout-menu-trigger");+ expect(getFallbackSVG(trigger)).not.toBeNull();+ // The marble gradient must be seeded by the user's handle, not a constant.+ expect(getFallbackSVG(trigger)).toBe(getFallbackSVG(reference.container));});test("new layout renders the organization switcher header trigger", () => {diff --git a/autogpt_platform/frontend/src/components/layout/Navbar/components/AccountMenu/components/AccountMenuHeader.tsx b/autogpt_platform/frontend/src/components/layout/Navbar/components/AccountMenu/components/AccountMenuHeader.tsxindex 065d3accec..e458743f6e 100644--- a/autogpt_platform/frontend/src/components/layout/Navbar/components/AccountMenu/components/AccountMenuHeader.tsx+++ b/autogpt_platform/frontend/src/components/layout/Navbar/components/AccountMenu/components/AccountMenuHeader.tsx@@ -14,6 +14,7 @@ import { Icon } from "@/components/atoms/Icon/Icon";interface Props {userName?: string;+ userHandle?: string;userEmail?: string;avatarSrc?: string;isLoading?: boolean;@@ -21,6 +22,7 @@ interface Props {export function AccountMenuHeader({userName,+ userHandle,userEmail,avatarSrc,isLoading = false,@@ -37,7 +39,12 @@ export function AccountMenuHeader({aria-haspopup="true"data-testid="account-menu-org-trigger">- <InitialAvatar src={avatarSrc} name={userName} className="h-8 w-8" />+ <InitialAvatar+ src={avatarSrc}+ name={userName}+ username={userHandle}+ className="h-8 w-8"+ /><div className="flex min-w-0 flex-1 flex-col gap-0.5">{isLoading || !userName || !userEmail ? (<>diff --git a/autogpt_platform/frontend/src/components/layout/Navbar/components/AccountMenu/components/InitialAvatar.tsx b/autogpt_platform/frontend/src/components/layout/Navbar/components/AccountMenu/components/InitialAvatar.tsxindex dce530d382..eb275fe73b 100644--- a/autogpt_platform/frontend/src/components/layout/Navbar/components/AccountMenu/components/InitialAvatar.tsx+++ b/autogpt_platform/frontend/src/components/layout/Navbar/components/AccountMenu/components/InitialAvatar.tsx@@ -1,26 +1,21 @@-import Avatar, { AvatarImage } from "@/components/atoms/Avatar/Avatar";+import Avatar, {+ AvatarFallback,+ AvatarImage,+} from "@/components/atoms/Avatar/Avatar";import { cn } from "@/lib/utils";interface Props {src?: string;name?: string;+ username?: string;className?: string;}-export function InitialAvatar({ src, name, className }: Props) {- const initial = name?.trim().charAt(0).toUpperCase() || "U";-+export function InitialAvatar({ src, name, username, className }: Props) {return (<Avatar className={cn("h-10 w-10", className)}>- <div className="absolute inset-0 z-0 flex items-center justify-center bg-violet-500 text-sm font-semibold text-white">- {initial}- </div>- <AvatarImage- src={src}- alt=""- aria-hidden="true"- className="relative z-10"- />+ <AvatarImage src={src} alt="" aria-hidden="true" />+ <AvatarFallback aria-hidden="true">{username || name}</AvatarFallback></Avatar>);}diff --git a/autogpt_platform/frontend/src/components/layout/Navbar/components/AccountMenu/components/__tests__/InitialAvatar.test.tsx b/autogpt_platform/frontend/src/components/layout/Navbar/components/AccountMenu/components/__tests__/InitialAvatar.test.tsxindex f8ecaf54e2..147ff7c5c7 100644--- a/autogpt_platform/frontend/src/components/layout/Navbar/components/AccountMenu/components/__tests__/InitialAvatar.test.tsx+++ b/autogpt_platform/frontend/src/components/layout/Navbar/components/AccountMenu/components/__tests__/InitialAvatar.test.tsx@@ -2,25 +2,64 @@ import { render, screen, waitFor } from "@/tests/integrations/test-utils";import { describe, expect, test } from "vitest";import { InitialAvatar } from "../InitialAvatar";+function getFallbackSVG(container: HTMLElement) {+ const svg = container.querySelector("svg");+ return svg?.innerHTML.replace(/:r[0-9a-z]+:/g, "id") ?? null;+}+describe("InitialAvatar", () => {- test("renders uppercase first character of name", () => {- render(<InitialAvatar name="abhimanyu" />);- expect(screen.getByText("A")).toBeDefined();+ test("renders marble gradient fallback when no image is provided", () => {+ const { container } = render(<InitialAvatar name="abhimanyu" />);+ expect(getFallbackSVG(container)).not.toBeNull();});- test("trims whitespace before extracting initial", () => {- render(<InitialAvatar name=" beth" />);- expect(screen.getByText("B")).toBeDefined();+ test("seeds the gradient deterministically by name", () => {+ const first = render(<InitialAvatar name="ada" />);+ const second = render(<InitialAvatar name="ada" />);+ const other = render(<InitialAvatar name="beth" />);++ expect(getFallbackSVG(first.container)).toBe(+ getFallbackSVG(second.container),+ );+ expect(getFallbackSVG(first.container)).not.toBe(+ getFallbackSVG(other.container),+ );});- test("falls back to 'U' when name is missing", () => {- render(<InitialAvatar />);- expect(screen.getByText("U")).toBeDefined();+ test("trims the name before seeding the gradient", () => {+ const padded = render(<InitialAvatar name=" beth" />);+ const plain = render(<InitialAvatar name="beth" />);+ expect(getFallbackSVG(padded.container)).toBe(+ getFallbackSVG(plain.container),+ );});- test("falls back to 'U' when name is an empty string", () => {- render(<InitialAvatar name="" />);- expect(screen.getByText("U")).toBeDefined();+ test("falls back to the 'User' seed when name is missing or empty", () => {+ const missing = render(<InitialAvatar />);+ const empty = render(<InitialAvatar name="" />);+ const user = render(<InitialAvatar name="User" />);++ expect(getFallbackSVG(missing.container)).toBe(+ getFallbackSVG(user.container),+ );+ expect(getFallbackSVG(empty.container)).toBe(+ getFallbackSVG(user.container),+ );+ });++ test("prefers username over display name as the gradient seed", () => {+ const withUsername = render(+ <InitialAvatar name="Ada Lovelace" username="ada" />,+ );+ const usernameOnly = render(<InitialAvatar name="ada" />);+ const nameOnly = render(<InitialAvatar name="Ada Lovelace" />);++ expect(getFallbackSVG(withUsername.container)).toBe(+ getFallbackSVG(usernameOnly.container),+ );+ expect(getFallbackSVG(withUsername.container)).not.toBe(+ getFallbackSVG(nameOnly.container),+ );});test("merges className prop into the avatar root", () => {@@ -31,17 +70,16 @@ describe("InitialAvatar", () => {expect(root.className).toContain("size-12");});- test("places image above the initial fallback when src is provided", async () => {+ test("shows a decorative image when src is provided", async () => {const { container } = render(<InitialAvatar name="ada" src="https://example.com/avatar.png" />,);await waitFor(() => {- expect(container.querySelector("img")).not.toBeNull();+ const image = container.querySelector("img");+ expect(image).not.toBeNull();+ expect(image?.getAttribute("aria-hidden")).toBe("true");});-- const image = container.querySelector("img");- expect(image?.className).toContain("z-10");- expect(screen.getByText("A").className).toContain("z-0");+ expect(screen.queryByRole("img")).toBeNull();});});diff --git a/autogpt_platform/frontend/src/components/layout/Navbar/components/MobileNavbar/MobileNavBar.tsx b/autogpt_platform/frontend/src/components/layout/Navbar/components/MobileNavbar/MobileNavBar.tsxindex ae48ffc111..da3746eb20 100644--- a/autogpt_platform/frontend/src/components/layout/Navbar/components/MobileNavbar/MobileNavBar.tsx+++ b/autogpt_platform/frontend/src/components/layout/Navbar/components/MobileNavbar/MobileNavBar.tsx@@ -82,9 +82,7 @@ export function MobileNavBar({src={avatarSrc}alt={userName || "Unknown User"}/>- <AvatarFallback>- {userName?.charAt(0) || "U"}- </AvatarFallback>+ <AvatarFallback>{userName}</AvatarFallback></Avatar><div className="relative h-14 w-full"><div className="absolute left-0 top-0 text-lg font-semibold leading-7 text-[#474747]">